Programming Tutorials

Python Tutorials

21. Overloading in python

By: Mariyan : 2012-04-07

Description: This answer on how to overload in python actually applies to all methods, but the question usually comes up first in the context of constructors.


22. switch case statement in Python

By: Mariyan : 2012-04-07

Description: There is no switch or case statement in Python. Because, you can do this easily enough with a sequence of if... elif... elif... else. There have been some proposals for switch statement syntax, but there is no consensus (yet) on whether and how to do range tests. For cases where you need to choose from a very large number of possibilities, you can create a dictionary mapping case values to functions to call. For example


23. Garbage Collection in Python

By: Kareem : 2012-04-07

Description: The details of Python memory management depend on the implementation. The standard C implementation of Python uses reference counting to detect inaccessible objects, and another mechanism to collect reference cycles, periodically executing a cycle detection algorithm which looks for inaccessible cycles and deletes the objects involved. The gc module provides functions to perform a garbage collection, obtain debugging statistics, and tune the collector's parameters.


24. goto in Python

By: Kareem : 2012-04-07

Description: You can use exceptions to provide a 'structured goto' that even works across function calls. Many feel that exceptions can conveniently emulate all reasonable uses of the 'go' or 'goto' constructs of C, Fortran, and other languages. For example


25. with in Python

By: Kareem : 2012-04-07

Description: Python has a 'with' statement that wraps the execution of a block, calling code on the entrance and exit from the block. Some language have a construct that looks like this:


26. Convert number to string in python

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


27. Convert string to number in python

By: Python Team : 2012-04-07

Description: For integers, use the built-in int() type constructor, e.g. int('144') == 144. Similarly, float() converts to floating-point, e.g. float('144') == 144.0.


28. Hexadecimal and Octal integers in python

By: Python Team : 2012-04-07

Description: To specify an octal digit, precede the octal value with a zero, and then a lower or uppercase 'o'. For example, to set the variable 'a' to the octal value '10' (8 in decimal), type:


29. Ternary operator in python

By: Python Team : 2012-04-07

Description: C language's ternary operator equivalent was added in Python 2.5. The syntax would be as follows


30. Callable objects in python

By: Python Team : 2012-04-07

Description: You can make a higher order function in Python using two choices: you can use nested scopes or you can use callable objects. For example, suppose you wanted to define linear(a,b) which returns a function f(x) that computes the value a*x+b. Using nested scopes: