This is O.R.Senthil Kumaran's blogspot on programming and technical things. The title is a line from "Zen of Python".
enumerate function in python; pyTip
When looping through a sequence, the position index and corresponding value can be retrieved at the same time using the enumerate() function.
>>> for i, v in enumerate(['tic', 'tac', 'toe']):
... print i, v
...
0 tic
1 tac
2 toe
>>> for i, v in enumerate(['tic', 'tac', 'toe']):
... print i, v
...
0 tic
1 tac
2 toe
pydoc humor
Attributes may be read-only or writable. In the latter case, assignment to attributes is possible. Module attributes are writable: you can write "modname.the_answer = 42". Writable attributes may also be deleted with the del statement. For example, "del modname.the_answer" will remove the attribute the_answer from the object named by modname.
Python QnA
Q) How do you reverse a string in python?
A) str = "Senthil"
str[-1::-1]
Using the slicing operator which takes three arguments.
A) str = "Senthil"
str[-1::-1]
Using the slicing operator which takes three arguments.
Subscribe to:
Posts (Atom)