Sunday, 15 September 2013

python - inverse characters from a string using 'for i in string' -



python - inverse characters from a string using 'for i in string' -

in python there way inverse string using 'for in string' starting lastly char rather first? avoid using counte rand not want utilize inverse. feedback!

string = 'caramelosticosis' new_string = '' cont = 0 in string: cont+=1 new_string += string[-cont] print(new_string)

easiest way utilize slice:

text = 'caramelosticosis' print(text[::-1])

(by way, best not utilize string variable name name of module)

python

No comments:

Post a Comment