Data Types
Types
#!/usr/bin/python

import sys;
import decimal
import fractions;

# int
n1 = 10;
print type(n1);

# long
n3 = 100L;
print type(n3);

# float
n2 = 3.14;
print type(n2);
#print sys.float_info;

# complex
n4 = complex(5, 10);
print type(n4);
print n4, n4.real, n4.imag;

# fraction
n5 = fractions.Fraction(1, 2);
print type(n5);

# decimal
n8 = decimal.Decimal('0.1');
print type(n8);
		
Arithmetic
#!/usr/bin/python

# int
n1 = 10;
n2 = 3;
print n1+n2;# 13
print n1-n2;# 7
print n1*n2;# 30
print n1/n2;# 3
print n1//n2;# 3
print n1%n2;# 1
print divmod(n1, n2);# (3, 1)
print pow(n1, n2);# 1000
print n1**n2;# 1000
			
#!/usr/bin/python

# float
n1 = 3.14;
n2 = 2.0;
print n1+n2;# 5.14
print n1-n2;# 1.14
print n1*n2;# 6.28
from __future__ import division; # include both / and //
print n1/n2;# 1.57, true division
print n1//n2;# 1, floor division
print n1%n2;# 1.14
print divmod(n1, n2);# (1, 1.14)
print pow(n1, n2);# 9.8596
print n1**n2;# 9.8596
		
True and False
#!/usr/bin/python

x = (1 < 2);# True
y = (1 == 1);# True

print (x or y);# True
print (x and y);# True
print (not x);# False
			
Bit Operations
#!/usr/bin/python

x = 5;
y = 10;

print bin(x);#101
print bin(y);#1010
print 'or: ', x|y, bin(x|y);#15, 1111
print 'and: ', x&y, bin(x&y);#0, 0
print 'exclusive: ', x^y, bin(x^y);#15, 1111
print 'shifted left: ', x<<2, bin(x<<2), x;#20, 10100, 5
print 'shifted right: ', x>>2, bin(x>>2), x;#1, 1, 5
print 'bit length: ', x.bit_length(), y.bit_length();#3 4
print 'not: ', ~x, bin(~x);#-6, -110
			
Override Functions
#!/usr/bin/python

# int
n1 = 10;
print type(n1);

print dir(n1);
print n1.__str__();
print n1.__sizeof__();
print n1.__pow__(2);
print n1.__add__(10);
print n1.__rand__
print n1.__hash__();
print n1.__index__();
print type(n1.__repr__());
			
Reference