-
Notifications
You must be signed in to change notification settings - Fork 2
/
8_operators.py
87 lines (73 loc) · 2.43 KB
/
8_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
76
77
78
79
80
81
82
83
84
85
86
87
#This is a python script to demonstrate operators
#Arithmetic operators
#Addition
x = 5
y = 3
print(x + y)
#Subtraction
x = 5
y = 3
print(x - y)
#Multiplication
x = 5
y = 3
print(x * y)
#Division
x = 5
y = 3
print(x / y)
#Modulus
x = 5
y = 3
print(x % y)
#Exponentiation
x = 5
y = 3
print(x ** y)
#Floor division
x = 5
y = 3
print(x // y)
#Assignment operators
#Assigns values from right side operands to left side operand
#x = 5 is a simple assignment operator that assigns the value 5 on the right to the variable x on the left
#x += 3 is a compound assignment operator that performs addition and then assigns the value to the variable x
#x -= 3 is a compound assignment operator that performs subtraction and then assigns the value to the variable x
#x *= 3 is a compound assignment operator that performs multiplication and then assigns the value to the variable x
#x /= 3 is a compound assignment operator that performs division and then assigns the value to the variable x
#x %= 3 is a compound assignment operator that performs modulus and then assigns the value to the variable x
#x //= 3 is a compound assignment operator that performs floor division and then assigns the value to the variable x
#x **= 3 is a compound assignment operator that performs exponentiation and then assigns the value to the variable x
#Comparison operators
#Returns True if the statement is true, otherwise False
#== is equal to
#!= is not equal to
#> is greater than
#< is less than
#>= is greater than or equal to
#<= is less than or equal to
#Logical operators
#and - Returns True if both statements are true
#or - Returns True if one of the statements is true
#not - Reverse the result, returns False if the result is true
#Identity operators
#is - Returns True if both variables are the same object
#is not - Returns True if both variables are not the same object
#Membership operators
#in - Returns True if a sequence with the specified value is present in the object
#not in - Returns True if a sequence with the specified value is not present in the object
#Bitwise operators
#& - Binary AND
#| - Binary OR
#^ - Binary XOR
#~ - Binary Ones Complement
#<< - Binary Left Shift
#>> - Binary Right Shift
#Python has the following data types built-in by default, in these categories:
#Text Type: str
#Numeric Types: int, float, complex
#Sequence Types: list, tuple, range
#Mapping Type: dict
#Set Types: set, frozenset
#Boolean Type: bool
#Binary Types: bytes, bytearray, memoryview