11. Convert number to string in python
By: Python Documentation Team : 2012-04-07
Description: To convert, e.g., the number 144 to the string ‘144’, use the built-in type constructor str(). If you want a hexadecimal or octal representation, use the built-in functions hex() or oct(). For fancy formatting, see the String Formatting section,
Read the full article
 
12. Perl's chomp() equivalent for removing trailing newlines from strings in python
By: Python Documentation Team : 2012-04-07
Description: Starting with Python 2.2, you can use S.rstrip("\r\n") to remove all occurrences of any line terminator from the end of the string S without removing other trailing whitespace. If the string S represents more than one line, with several empty lines at the end, the line terminators for all the blank lines will be removed
Read the full article
 
13. Convert between tuples and lists in python
By: Python Documentation Team : 2012-04-07
Description: The type constructor tuple(seq) converts any sequence (actually, any iterable) into a tuple with the same items in the same order.
Read the full article
 
14. Iterate over a sequence in reverse order in python
By: Python Documentation Team : 2012-04-07
Description: Use the reversed() built-in function, which is new in Python 2.4
Read the full article
 
15. Remove duplicates from a list in python
By: Python Documentation Team : 2012-04-07
Description: If you don’t mind reordering the list, sort it and then scan from the end of the list, deleting duplicates as you go
Read the full article
 
16. Array in python
By: Python Documentation Team : 2012-04-07
Description: Lists are equivalent to C or Pascal arrays in their time complexity; the primary difference is that a Python list can contain objects of many different types.
Read the full article
 
17. Multidimensional list (array) in python
By: Python Documentation Team : 2012-04-07
Description: The reason is that replicating a list with * doesn’t create copies, it only creates references to the existing objects. The *3 creates a list containing 3 references to the same list of length two. Changes to one row will show in all rows, which is almost certainly not what you want.
Read the full article
 
18. Schwartzian Transform in python
By: Python Documentation Team : 2012-04-07
Description: The technique, attributed to Randal Schwartz of the Perl community, sorts the elements of a list by a metric which maps each element to its "sort value". In Python, just use the key argument for the sort() method
Read the full article
 
19. Delegation in python
By: Python Documentation Team : 2012-04-07
Description: Delegation is an object oriented technique (also called a design pattern). Let's say you have an object x and want to change the behaviour of just one of its methods. You can create a new class that provides a new implementation of the method you're interested in changing and delegates all other methods to the corresponding method of x.
Read the full article
 
20. Static in python
By: Python Documentation Team : 2012-04-07
Description: Both static data and static methods (in the sense of C++ or Java) are supported in Python. For static data, simply define a class attribute. To assign a new value to the attribute, you have to explicitly use the class name in the assignment
Read the full article
 

Previous      Next