operators
This commit is contained in:
76
src/basic/basic_operators.py
Normal file
76
src/basic/basic_operators.py
Normal file
@@ -0,0 +1,76 @@
|
||||
a = 15
|
||||
b = 4
|
||||
|
||||
# Addition
|
||||
print("Addition:", a + b) # Addition: 19
|
||||
|
||||
# Subtraction
|
||||
print("Subtraction:", a - b) # Subtraction: 11
|
||||
|
||||
# Multiplication
|
||||
print("Multiplication:", a * b) # Multiplication: 60
|
||||
|
||||
# Division
|
||||
print("Division:", a / b) # Division: 3.75
|
||||
|
||||
# Floor Division
|
||||
print("Floor Division:", a // b) # Floor Division: 3
|
||||
|
||||
# Modulus
|
||||
print("Modulus:", a % b) # Modulus: 3
|
||||
|
||||
# Exponentiation
|
||||
print("Exponentiation:", a ** b) # Exponentiation: 50625
|
||||
|
||||
# Comparison Operators in Python
|
||||
a = 13
|
||||
b = 33
|
||||
|
||||
print(a > b) # False
|
||||
print(a < b) # True
|
||||
print(a == b) # False
|
||||
print(a != b) # True
|
||||
print(a >= b) # False
|
||||
print(a <= b) # True
|
||||
|
||||
# Logical Operators in Python
|
||||
|
||||
a = True
|
||||
b = False
|
||||
|
||||
print(a and b) # False
|
||||
print(a or b) # True
|
||||
print(not a) # False
|
||||
|
||||
|
||||
# Assignment Operators in Python
|
||||
a = 10
|
||||
b = a
|
||||
|
||||
print(b) # 10
|
||||
|
||||
b += a
|
||||
print(b) # 20
|
||||
|
||||
b -= a
|
||||
print(b) # 10
|
||||
|
||||
b *= a
|
||||
print(b) # 100
|
||||
|
||||
# Identity Operators in Python
|
||||
a = 10
|
||||
b = 20
|
||||
c = a
|
||||
|
||||
print(a is not b) # True
|
||||
print(a is c) # True
|
||||
|
||||
# Ternary Operator in Python
|
||||
a = 10
|
||||
b = 20
|
||||
|
||||
print("a is greater" if a > b else "b is greater")
|
||||
|
||||
|
||||
# There No ++ and -- Operators in Python
|
||||
@@ -18,6 +18,11 @@
|
||||
- Windows/macOS (default FS): `MyFile.py` == `myfile.py`
|
||||
- Linux: case-sensitive — they’re different files.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
## 2. PEP 8 Style Recommendations (Best Practices)
|
||||
|
||||
@@ -68,3 +68,4 @@ x = "string now" # Allowed
|
||||
|
||||
type(x) # <class 'str'>
|
||||
isinstance(x, str) # True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user