forked from thewhitetulip/SamplePythonScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
builtinTypes.py
68 lines (51 loc) · 1.13 KB
/
builtinTypes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#The principal built-in types are numerics, sequences, mappings, files, classes, instances and exceptions.
#boolean operators
print 23 or False #prints 23
print 23 and False #print False
print not 23 #prints False
#comparisons operators
print 4>3 #prints True
print 4<3 #prints False
print 4==3 #prints False
print 4<=3 #prints False
print 4>=3 #prints True
print 4!=2 #prints True
print type(3) is int #prints True
print type('3') is not int # prints True
#operations
#x=23, =24
print x + y
print x - y
print x * y
print x / y
print x // y
print x % y
print -x
print +x
print abs(x)
print int(x)
print long(x)
print float(x)
print complex(re,im)
print c.conjugate()
print divmod(x, y)
print pow(x, y)
print x ** y
#bitwise operations on int
print x | y
print x ^ y
print x & y
print x << n
print x >> n
print ~x
#methods on Integer types
n = 30
print n.bit_length() #returns the length of binary of 30
#same with long
#additional methods on float
a = 4.5
a.as_integer_ratio() #returns a tuple as humans write fractions
a=2.0
print a.is_integer() # true
print a.hex() #prints hex of a
print a.fromhex('0x004') #returns float of hex value