Python Basics
Your First Steps into Python Programming
■ Level 1 — Absolute Beginner
1. What is Python?
Python is a high-level, interpreted programming language known for its clean, readable syntax.
Created by Guido van Rossum and first released in 1991, Python is today used in web development,
data science, automation, artificial intelligence, and much more.
• Easy to read and write — great for beginners
• Huge standard library and third-party ecosystem (PyPI)
• Cross-platform: runs on Windows, macOS, Linux
• Interpreted — no separate compilation step needed
2. Installation & First Program
Installing Python
Download the latest Python installer from [Link]. During installation on Windows, tick Add
Python to PATH. Verify the installation by opening a terminal and typing:
python --version
# Expected output: Python 3.x.x
Hello, World!
Create a file called [Link] and add the following line:
print("Hello, World!")
Run it from your terminal:
python [Link]
# Output: Hello, World!
3. Variables & Data Types
A variable is a name that stores a value. Python is dynamically typed — you don't declare types.
name = 'Saketh' # str (string)
age = 17 # int (integer)
gpa = 9.8 # float
passed = True # bool (True / False)
print(type(name)) # <class 'str'>
print(type(age)) # <class 'int'>
Type Example Use Case
int 42, -7, 0 Whole numbers
float 3.14, -0.5 Decimal numbers
str 'hello', "world" Text
bool True, False Conditions / flags
NoneType None Absence of a value
4. Operators
Arithmetic Operators
a, b = 10, 3
print(a + b) # 13 — addition
print(a - b) # 7 — subtraction
print(a * b) # 30 — multiplication
print(a / b) # 3.333... — true division
print(a // b) # 3 — floor division
print(a % b) # 1 — modulus (remainder)
print(a ** b) # 1000 — exponentiation
Comparison & Logical Operators
print(5 > 3) # True
print(5 == 5) # True
print(5 != 3) # True
print(True and False) # False
print(True or False) # True
print(not True) # False
5. User Input & Output
name = input('Enter your name: ')
age = int(input('Enter your age: '))
print(f'Hello {name}! You are {age} years old.')
# f-strings (formatted string literals) — Python 3.6+
pi = 3.14159
print(f'Pi is approximately {pi:.2f}') # Pi is approximately 3.14
■ Tip: Always convert input() to the right type. input() always returns a string!
6. Conditional Statements
marks = int(input('Enter your marks: '))
if marks >= 90:
print('Grade: A')
elif marks >= 75:
print('Grade: B')
elif marks >= 60:
print('Grade: C')
else:
print('Grade: F')
7. Loops
for Loop
# Loop over a range
for i in range(1, 6):
print(i) # prints 1 2 3 4 5
# Loop over a string
for char in 'Python':
print(char)
while Loop
count = 1
while count <= 5:
print(count)
count += 1
# break and continue
for i in range(10):
if i == 7:
break # exit loop
if i % 2 == 0:
continue # skip even numbers
print(i) # prints 1 3 5
8. Practice Problems
• Write a program that prints multiplication table of any number entered by the user.
• Write a program to check whether a number is prime.
• Write a program to find the factorial of a number using a loop.
• Write a program to print Fibonacci series up to n terms.
• Write a program that counts vowels in a sentence entered by the user.
Quick Reference Card
Concept Syntax / Example
Print print('hello')
Variable x = 10
Input name = input('Enter: ')
If-Else if x > 0: ... else: ...
For Loop for i in range(5): ...
While Loop while x > 0: ...
String Format f'Value is {x}'
Type Cast int('5'), float('3.14'), str(42)