Essential Python syntax
🔰 1. Basic Syntax
# Comments
# Single-line comment
''' Multi-line
comment '''
""" Multi-line
comment """
# Print Statement
print("Hello, World!")
# Variables
x = 5
name = "Alice"
🧮 2. Data Types
# Numeric
int_num = 10
float_num = 10.5
complex_num = 3 + 4j
# Boolean
status = True
# String
greet = "Hello"
# List
fruits = ["apple", "banana", "cherry"]
# Tuple
coordinates = (4, 5)
# Set
unique_items = {1, 2, 3}
# Dictionary
student = {"name": "Alice", "age": 20}
🧮 3. Operators
🔹 1. Arithmetic Operators
Operator Description Example Output
+ Addition 10 + 5 15
- Subtraction 10 - 5 5
* Multiplication 10 * 5 50
/ Division 10 / 5 2.0
// Floor Division 10 // 3 3
% Modulus (Remainder) 10 % 3 1
** Exponentiation 2 ** 3 8
🔹 2. Assignment Operators
Operator Example Equivalent To
= x = 5 Assign value 5 to x
+= x += 3 x = x + 3
-= x -= 2 x = x - 2
*= x *= 4 x = x * 4
/= x /= 2 x = x / 2
//= x //= 2 x = x // 2
%= x %= 3 x = x % 3
**= x **= 2 x = x ** 2
🔹 3. Comparison (Relational) Operators
Operator Description Example Output
== Equal to 5 == 5 True
!= Not equal to 5 != 3 True
> Greater than 5 > 3 True
< Less than 5 < 3 False
>= Greater than or equal 5 >= 5 True
<= Less than or equal 3 <= 5 True
🔹 4. Logical Operators
Operator Description Example Output
and Logical AND True and False False
or Logical OR True or False True
not Logical NOT not True False
🔹 5. Bitwise Operators
Operator Description Example Output
& Bitwise AND 5 & 3 → 101 & 011 1
` ` Bitwise OR `5
^ Bitwise XOR 5 ^ 3 6
~ Bitwise NOT ~5 -6
<< Left Shift 5 << 1 10
>> Right Shift 5 >> 1 2
🔹 6. Membership Operators
Operator Description Example Output
in True if value is present 'a' in 'apple' True
not in True if value is not present 'z' not in 'apple' True
🔹 7. Identity Operators
Operator Description Example Output
is True if same object a is b True/False
is not True if not same object a is not b True/False
🔁 4. Control Structures
Conditional Statements
if x > 0:
print("Positive")
elif x == 0:
print("Zero")
else:
print("Negative")