Skip to content

Commit 9ff04ee

Browse files
committed
added builtinTypes.pu
1 parent e00cf71 commit 9ff04ee

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

builtinTypes.py

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

0 commit comments

Comments
 (0)