Basic Input Output
# Program to take name and age and display a message name = input("Enter your name: ") age =
int(input("Enter your age: ")) print("Hello", name) print("You will be", age + 1, "years old next year")
Data Types
# Demonstrating different data types a = 10 b = 3.5 c = "Python" d = True print(type(a), type(b),
type(c), type(d))
Operators
# Arithmetic operators a = 10 b = 3 print(a + b, a - b, a * b, a / b, a % b)
Conditional Statements
# Check whether a number is even or odd num = int(input("Enter a number: ")) if num % 2 == 0:
print("Even") else: print("Odd")
Loops
# Print first 10 natural numbers using loop for i in range(1, 11): print(i)
Strings
# String operations s = "Computer Science" print([Link]()) print([Link]()) print(len(s))
Lists
# List operations numbers = [1, 2, 3, 4, 5] [Link](6) [Link](3) print(numbers)
Tuples
# Tuple example t = (10, 20, 30) print(t[1]) print(len(t))
Dictionary
# Dictionary example student = {"name": "Aman", "class": 11, "marks": 85} print(student["name"])
print([Link]())
Functions
# Function to calculate square of a number def square(n): return n * n print(square(5))
File Handling
# Write and read from a file f = open("[Link]", "w") [Link]("Hello File") [Link]() f = open("[Link]",
"r") print([Link]()) [Link]()
Modules
# Using math module import math print([Link](16)) print([Link](5))