-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03operators.py
More file actions
105 lines (64 loc) · 1.86 KB
/
03operators.py
File metadata and controls
105 lines (64 loc) · 1.86 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
'''
Operators in Python:
- Operators are symbols for performing operations
- Values operands
- Symbol: operator
For eg:
a+b
where +: operator, and a,b: operands
Different types of operators are as follows:
1. Arithmetic Operators:
- Addition (+), Subtraction (-), Multiplication (*), Division (/)
- Modulus (%), Exponentiation (**), Floor division (//)
2. Comparison Operators:
- Equal (==), Not equal (!=), Greater than (>), Less than (<)
- Greater than or equal to (>=), Less than or equal to (<=)
3. Logical Operators:
- and, or, not
4. Assignment Operators:
- Equals (=), Add and assign (+=), Subtract and assign (-=)
- Multiply and assign (*=), Divide and assign (/=), etc.
5. Bitwise Operators:
- AND (&), OR (|), XOR (^), NOT (~)
- Shift left (<<), Shift right (>>)
6. Membership Operators:
- in, not in
7. Identity Operators:
- is, is not
These operators allow you to perform various operations on variables and values in your Python programs.
'''
# Arithmetic Operators
#input is taken from the user and converted to integer
a = int(input("Enter first number"))
b = int(input("Enter second number"))
# Addition
print(a + b) # Output: 15
# Subtraction
print(a - b) # Output: 5
# Multiplication
print(a * b) # Output: 50
# Division
print(a / b) # Output: 2.0
# Modulus
print(a % b) # Output: 0
# Exponentiation
print(a ** b) # Output: 1000
# Floor division
print(a // b) # Output: 2
# Comparison Operators
print(a == b) # Output: False
print(a!= b) # Output: True
print(a > b) # Output: True
print(a < b) # Output: False
print(a >= b) # Output: True
print(a <= b) # Output: False
# Logical Operators
print(True and False) # Output: False
print(True or False) # Output: True
print(not True) # Output: False
# Assignment Operators
c = a
print(c) # Output: 10
c += b
print(c) # Output: 15
c -= b