| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

python

Page history last edited by Sérgio Luiz Araújo Silva 12 years, 6 months ago

Introdução

Minhas anotações sobre python

 

help('string')

 

retorna uma ajuda sobre o tipo string

 

Inverter strings

source: http://aprenda-python.blogspot.com/2011/09/inverter-strings.html

 

 

Dada uma string, quero mostrá-la invertida. Em python é muito simples.

>>> 'eu gosto de python'[::-1]
'nohtyp ed otsog ue'

E se eu quiser inverter palavra por palavra, mas mantendo a ordem em que as palavras aparecem no texto?

>>> ' '.join([word[::-1] for word in 'eu gosto de python'.split()])
'ue otsog ed nohtyp'

Comments (0)

You don't have permission to comment on this page.