1.
Basic Python Syntax
• Python is case-sensitive
• Uses indentation (spaces) instead of
braces {}
• Statements usually end at a new line
(no semicolon needed)
if x > 5:
print("Hello")
2. Variables
• A variable is a name that stores a value.
• Must start with a letter or underscore
• Cannot start with a number
• No special characters except
• Cannot use Python keywords
age = 20
name = "Alex"
_marks = 95
3. Data Types
Common Built-in Data Types
Type Example
int 10, -5
float 3.14, 2.0
str "hello", 'Python'
bool True, False
list [1, 2, 3]
tuple (1, 2, 3)
set {1, 2, 3}
dict {"a": 1, "b": 2}
4. Type Casting
Converting one data type to another.
int("5") # 5
float(3) # 3.0
str(10) # "10"
5. Operators
Arithmetic Operators
• + # Addition
• - # Subtraction
• * # Multiplication
• / # Division
• % # Modulus
• ** # Exponent
• // # Floor division
Relational (Comparison)
Operators
==
!=
>
<
>=
<=
Returns True or False
Logical Operators
• and
• or
• not
Assignment Operators
• =
• +=
• -=
• *=
• /=
• %=
Input and Output
Output (print)
print("Hello World")
print("Age:", 20)
Multiple values:
print("Sum =", a + b)
Input
input() always takes string input
name = input("Enter your name: ")
Comments
Single-line comment
# This is a comment
Multi-line comment
"""
This is a
multi-line comment
"""