How to reverse a string?
How to read from console in Python?
Want to read an integer?
Swap values in python:
My motivation to learn python is: life is short - you need Python
s = 'abcdef' s = s[::-1] print sExplanation: "::" is known as stride notation
s[::2] s[::-2]Returns "ace" and "fdb" respectively.
How to read from console in Python?
name = raw_input()
Want to read an integer?
num = raw_input() num = int(num) # raw_input returns string, so convert it to integer
Swap values in python:
a, b = b, a
My motivation to learn python is: life is short - you need Python
No comments:
Post a Comment