-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path02-arithmatic-operators.py
76 lines (59 loc) · 1.46 KB
/
02-arithmatic-operators.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
66
67
68
69
70
71
72
73
74
75
# HEAD
# Arithmatic Operators
# DESCRIPTION
# Describes all the operators related to arithmatic
# RESOURCES
#
# Different operators are available for
# + , - , * , / , %, //
# Addition Operator
add = 1 + 2
# Result > 3
print('add:', add)
addStrings = "stringone" + "string2"
# Result > "stringonestring2"
print('addStrings:', addStrings)
# addNumAndString = 1 + "string"
# # Result > Error due to different data types
# print('addNumAndString:', addNumAndString)
# Negative Operator
sub = 2 - 1
# Result > 1
print('sub:', sub)
# Multiplication Operator
mul = 2 * 1
# Result > 2
print('mul:', mul)
# Division Operator
div = 2/1
# Result > 2
print('div:', div)
# Modulus Operator - Remainder
mod = 10%2
# Result > 0
print('mod:', mod)
# Modulus Operator - Quotient
quo = 10//2
# Result > 5
print('quo:', quo)
# Precedence of operators
# / , * , - , +
# Using operators for string
strjoin = "Test" + " and Tester"
print('strjoin:', strjoin)
# # Using operators for string and integer
# strjoin = 1 + " and Tester"
# print('int and str join: Error', strjoin)
# Truthy value takes 1 as interger and Falsy as 0
# Adding two boolean Truthy Values
boolAdd = True + True
print("boolAdd", boolAdd)
# Adding two boolean Truthy and Falsy Values
boolAdd = True + False
print("boolAdd", boolAdd)
# Adding two boolean Truthy and Numeric Values
boolNumAdd = True + 2
print("boolNumAdd", boolNumAdd)
# Muliplying two boolean Truthy and Numeric Values
boolMul = True * 2
print("boolMul", boolMul)