Programming Tutorials

Python Tutorials

11. Python Basics - Setting up your Python Development Environment

By: William Alexander : 2017-09-26

Description: The first decision you need to make is which version to download. The Python 2.7 or the Python 3.x. If you are a beginner and you are just starting to learn Python, then you should download 3.x. On the other hand, if you need to work on some legacy Python based application which depends on older libraries that cannot be ported, then you are better off with 2.7. But moving forward, there will not be any new releases on 2.7 Python. Eventually all have to migrate to 3.x version which is improved and most of the libraries are porting to the newer version. So Just go with version 3.x. Download the right release based on whether you are using Windows, Linux or Mac. Just download and install it in the default location.


12. Convert between tuples and lists in python

By: Rajesh : 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.


13. Perl's chomp() equivalent for removing trailing newlines from strings in python

By: Python 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


14. Iterate over a sequence in reverse order in python

By: Rajesh : 2012-04-07

Description: Use the reversed() built-in function, which is new in Python 2.4


15. Remove duplicates from a list in python

By: Koothrapalli : 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


16. Array in python

By: Koothrapalli : 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.


17. Multidimensional list (array) in python

By: Koothrapalli : 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.


18. Schwartzian Transform in python

By: Koothrapalli : 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


19. Delegation in python

By: Koothrapalli : 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.


20. Static in python

By: Vijay : 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