Topic 1: Introduction to Python & Basic Syntax
What is Python?
Python is a high-level, interpreted, general-purpose programming language known
for its readability, simplicity, and versatility. It is widely used in web development,
data science, automation, AI, and software development.
• Developed by: Guido van Rossum
• First Released: 1991
• Latest Version: Python 3.x (3.12 at time of writing)
• Python is dynamically typed, supports object-oriented, functional, and
procedural programming.
Features of Python
• Simple and readable syntax
• Dynamically typed (no need to declare variable types)
• Interpreted language (executed line by line)
• Large standard library
• Portable and cross-platform
• Open-source and free
Installing Python
Install from the official website: https://www.python.org/downloads
After installation, verify by running:
python --version or python3 --version in terminal
First Python Program
print("Hello, World!")
Explanation:
• print() is used to display output on the screen.
P a g e 3 | 70
• Statements don’t require a semicolon at the end.
Python Basic Syntax Rules
1. Indentation is Mandatory
Used to define blocks (loops, functions, etc.)
Example:
if 5 > 2:
print("Five is greater than two")
2. Comments
o Single line: starts with #
Example: # This is a comment
o Multi-line: use triple quotes
Example:
'''
This is a
multi-line comment
'''
3. Case Sensitivity
Python is case-sensitive.
MyVar and myvar are different.
4. Variable Naming Rules
o Must start with a letter or underscore _
o Can contain letters, digits, underscores
o Cannot start with a digit or use reserved keywords
P a g e 4 | 70
Topic 2: Variables and Data Types
What is a Variable?
A variable in Python is used to store data that can be referenced and manipulated later
in the program. Python is dynamically typed — you don’t need to declare the type of a
variable.
Example:
x = 10
name = "Alice"
Data Types in Python
Data Type Example Description
int x = 10 Whole numbers
float y = 3.14 Decimal numbers
str name = "Bob" Sequence of characters
bool is_valid = True Boolean (True/False)
list nums = [1, 2, 3] Ordered, mutable collection
tuple t = (1, 2) Ordered, immutable collection
dict d = {"a": 1} Key-value pairs
set s = {1, 2, 3} Unordered, unique values
NoneType x = None Represents null or no value
2. Variable Naming Rules
1. Must begin with a letter (A-Z or a-z) or an underscore (_).
2. The rest of the name can contain letters, numbers, or underscores.
3. Variable names are case-sensitive (MyVar and myvar are different).
4. Cannot use Python’s reserved keywords (like for, class, if, etc.).
P a g e 5 | 70