Python is known for its simplicity and readability. This module builds the foundation required to write clean, error-free Python programs.
A variable is a container used to store data values in memory. Python does not require declaring the data type explicitly.
✅ Must start with a letter (a–z, A–Z) or underscore _
❌ Cannot start with a number
❌ Cannot use Python keywords
✅ Case-sensitive (age ≠ Age)
✅ Use meaningful names
age = 25
name = "Prakash"
salary = 45000.75
_is_active = True
student_name = "Rahul" # snake_case
Data types define the type of value a variable holds.
| Category | Data Types |
|---|---|
| Numeric | int, float, complex |
| Text | str |
| Boolean | bool |
| Sequence | list, tuple |
| Set | set |
| Mapping | dict |
| None | NoneType |
x = 10 # int
y = 10.5 # float
name = "Python" # string
is_valid = True # boolean
marks = [80, 90, 85] # list
print(type(x)) # <class 'int'>
Type casting means converting one data type into another.
int()float()str()bool()a = "10"
b = int(a) # string → int
x = 5
y = float(x) # int → float
num = 100
text = str(num) # int → string
int("Python") # ValueError
input() → Takes input from the userprint() → Displays outputname = input("Enter your name: ")
print("Welcome", name)
age = int(input("Enter your age: "))
print("Your age is", age)
print(f"My name is {name} and age is {age}")
Comments are used to explain code and improve readability.
# This is a single-line comment
"""
This is a multi-line comment
used for documentation
"""
def add(a, b):
"""This function returns sum of two numbers"""
return a + b
Keywords are reserved words with special meaning in Python.
if, else, elif, for, while, break, continue,def, return, class, try, except, finally,True, False, None, import, from, as, pass
if age >= 18:
print("Eligible to vote")
else:
print("Not eligible")
❌ Invalid:
class = 10 # Error
Python uses indentation instead of braces {} to define blocks of code.
if 10 > 5:
print("10 is greater")
print("Inside if block")
if 10 > 5:
print("Error") # IndentationError