Python Basics Training
Definitions with Examples
Print Statement
• Definition: Used to display output on the
screen.
• Example: print("Hello, World!")
Variables
• Definition: A container for storing data values.
• Example: x = 10
name = "Rhea"
Data Types
• Definition: Defines the type of data: int, float,
str, bool, list, tuple, dict, set.
• Example: age = 25
pi = 3.14
is_active = True
fruits = ["apple", "banana"]
Input & Type Casting
• Definition: Takes user input and converts it
into required type.
• Example: age = int(input("Enter age: "))
print("Next year:", age+1)
Operators
• Definition: Symbols used to perform
operations on values.
• Example: x = 5 + 3 # 8
print(10 > 5) # True
Conditionals
• Definition: Used to make decisions in code.
• Example: age = 18
if age >= 18:
print("Adult")
else:
print("Minor")
Loops
• Definition: Used to repeat code multiple
times.
• Example: for i in range(5):
print(i)
Functions
• Definition: A block of reusable code.
• Example: def greet(name):
return "Hello " + name
print(greet("Shivani"))
Lists
• Definition: Ordered, changeable collection of
items.
• Example: fruits = ["apple", "banana"]
fruits.append("mango")
Dictionaries
• Definition: Collection of key-value pairs.
• Example: person = {"name": "Shivani", "age":
25}
print(person["name"])
Modules & Libraries
• Definition: Pre-written code you can import
and use.
• Example: import math
print(math.sqrt(16))
Error Handling
• Definition: Used to handle errors and prevent
crashes.
• Example: try:
num = int("abc")
except ValueError:
print("Invalid number!")
File Handling
• Definition: Used to read from and write to
files.
• Example: with open("data.txt", "w") as f:
f.write("Hello")