This repo contains Python practical examples of certain topics like:
-
- Inheritance
-
- Method overriding in runtine
- Abstract methods
- Static methods
- var-args methods
- dictionary-typed arguments in methods
- mixed method types (var-args + kw-args)
- using global variables inside methods
- mutable arguments (changed with each call) in methods like on example below
def mutableArgsWarn(self, x=[]):
print "--- mutableArgsWarn ---"
x.append(1)
print x
print datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print datetime.strptime('Wed, 27 Oct 1770 22:17:00', '%a, %d %b %Y %H:%M:%S')
- Determining difference between two dates using timedelta
print "another year:",timedelta(weeks=40, days=84, hours=23, minutes=50, seconds=600)
-
Debugging using special variables builtin, sys, inspect
-
- examples of common file operations: read, write, delete, close
- saving objects to files in JSON format
- serializing and saving objects
- example of changing file names using regular expressions
-
- using comprehensions
- examples of the different loop types: for in, while
- using ternary operator
-
- using of timeit module to determine execution time of different variants of
- using of unittest
-
- matching the pattern using re.match
- finding all occurences of the pattern with re.findall
- iterate over matched results using re.finditer
- splitting string using regular expressions with re.split
- substituting the pattern using re.sub
- display matched results using match.group and match.groups
-
- Overriding operators using: lt, le, eq, ne, gt, ge
- Using function decorators (and simple explanation how this works)
- Defining descriptor classes (If class defines methods get, set, delete it's called descriptor)
- different using of import statement (wildcards, relative imports)
- overriding built-in functions: example of how override print function
- example of how to override mathematical operators behavior in classes
-
- in-place values swapping
- chaining of comparison operators
- using generators with yield keyword
- create classes on-the-fly
-
Special class methods examples: init,new,del,repr,str,getattr,cal
-
Urllib example usage in GET and POST requests (how to easy make get/post requests)