Since Python 2.4, int and long are unified. Furthermore, from Python 3, int is the only type for integer, which has the capacity of long in Python 2.
sys.maxint returns the maximum integer number that Python can hold.
def parse_bool(s): return s.lower() in ("yes", "true", "T", "1")
bool('foo') # True bool('') # FalseYou can not use the above function to parse boolean from string.
if isinstance(var, int): print("It is integer")On python 2:
if is instance(var, (int, long)): print("It is integer")
import sys if isinstance(var, basestring if sys.version_info[0]<3 else str): print("it is string") # var is string
x = true_value if condition else false_value
if isinstance(s, basestring if sys.version_info[0]<3 else str): print('It is a str.')
dict = { 'a':1, 'b':2 } dict = { k: str(dict[k]) for k in dict.keys() } print(dict)
class A: def __init__(self): pass def main(): print("Hello World") if __name__ == '__main__': main()