ong-z
9/27/2016 - 3:01 PM

basics.py

basics.py

# dictionary get() method
dict.get(key, default=None)
dict.pop(key, default=None)

# string types u and r
# tackoverflow.com/questions/2081640/what-exactly-do-u-and-r-string-flags-do-in-python-and-what-are-raw-string-l
# There are two types of string in python: the traditional str type and the newer unicode type. If you type a string literal without the u in front you get the old str type which stores 8-bit characters, and with the u in front you get the newer unicode type that can store any Unicode character.
# The r doesn't change the type at all, it just changes how the string literal is interpreted. Without the r, backslashes are treated as escape characters. With the r, backslashes are treated as literal. Either way, the type is the same.

# string functions
g = " abc de f  "
len(g)      # 11
g.strip()   # 'abc de f'

# great explanation of python class and static methods
http://stackoverflow.com/questions/136097/what-is-the-difference-between-staticmethod-and-classmethod-in-python