-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperatorss.py
More file actions
65 lines (52 loc) · 2.22 KB
/
operatorss.py
File metadata and controls
65 lines (52 loc) · 2.22 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
# Operators in python
# arithmetic operators- +,-,*,/,//, **,%
# Assignment operators
# Comparision operators
# Logical operators
# Identity operators
# Membership operators
# Bitwise operators
# 1. Arithmetic operators
#print("The sum of 2 and 3 is:", 2+3) # + sign is an arithmetic operator used
#print("The sub of 2 and 3 is:", 2-3)
#print("The mult of 2 and 3 is:", 2*3)
#print("The div of 2 and 3 is:", 2/3)
#print("15 // 6 is",15//6) # // is an operator that gives integer without decimals as 15/6 is 2.5 it leaves the five and prints 2
#print("5**6 is",5**6) # 5**6 means 5 raise to the power of 6
#print("remainder when 5 divides by 2 is",5%2) # % is the modulus operator that gives us the remainder
# 2. Assignment operator
#x=5
#x+=7 # assignment operators like +=, -=, /=, *= assigns a number to the variable that adds, subs, multi, or divides to it
#print(x)
# 3. Comparision Operators
#i=3
#print(i==4) #Boolena type operators as it shows if i is 4 or 3 by giving output in true or false
# != means not equals to and == means equals to
#print(i!=4) # true because i is not equal to 4
# <, >, <=, >= are also comparision operators which you can put in the print statement bracket
# 4. Logical operators
# and, or, not, is are logical operators
#i=3
#print(i and 4)
#a= True
#b= False
#print(a and a)# true
#print(a and b) #true and false will be false- boolean algebra
#print(b and b)# false
#print(a or b) # it will print the true onr
#print(a is b) # a is not b so output will be false
#print(a is not b) # a is not b so by boolean type it is true
# 4. Membership operators
# in, not in are type of membership operators
#list=[6,4,4,2,5,3,3,23,4,0,33]
#print(33 in list) # 33 is in list hence it will print true
#print(2324 not in list) # will be true as 2324 is not in list
# 5. Bitwise operators
# work with binary numbers
# &,| are some of the binary operators
#0=00
#1=01
#print(0 & 1) # the 0 and 1 in binary are shown as 00 and 01 where 0 with 0 vertically and 0 and 1 vertically
# is 0 again because of the first digits hence the output is 0
print(0|1) # | means or hence verticlaly 0 and 0 will be 0 in or and 0 and 1 vertically will be 1 hence
# 01 will print that is 1