-
Notifications
You must be signed in to change notification settings - Fork 0
/
Int, Float & Boolean.py
53 lines (47 loc) · 1.15 KB
/
Int, Float & Boolean.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
# basic operations
print (25 + 4) # 29
print (25 - 4) # 21
print (25 * 4) # 100
print (25 / 4) # 6.25
print (3 ** 4) # 81
print (25 % 4) # 1
print (25 // 4) # 6
print ()
# boolean operations
x = 3
y = 6
print (x < y) # True
print (x > y) # False
print (2 * x <= y) # True
print (2 * x >= y) # True
print (2 * x == y) # True
print (2 * x != y) # False
print ()
# data type initiation
x = int (4.7)
y = float (4)
print(round (12.345, 2))
print (x) # 4
print (y) # 4.0
# read type
print (type (x)) # (<class 'int'>), i.e., int
print (type (y)) # (<class 'float'>), i.e., float.
# concatinating strings for constants only
print('Py' 'thon')
print ('Py'
'thon')
# r-strings
# escapable characters are escaped
print('C:\some\name')
# escapable characters are not escaped
print(r'C:\some\name')
# multiple strings using triple-quotes: """, ''' as delimiters
print("""\
Usage: thingy [OPTIONS]
-h Display this usage message
-H hostname Hostname to connect to
""")
# floats are not exact
print (.1 + .1 + .1) # 0.30000000000000004
print (.3) # 0.3
print (.1 + .1 + .1 == .3) # 0.3 != 0.30000000000000004