Introductory Python
What is Python?
• Python is a high-level, interpreted, and general-purpose programming language.
• Created by Guido van Rossum and released in 1991.
• Known for its simplicity, readability, and wide usage.
• Used for: Web development, Data Science, Automation, Machine Learning,
Cybersecurity, Game Development, etc.
Basic Features of Python
• Easy to learn and use.
• Open-source and free.
• Portable (runs on Windows, macOS, Linux, etc.).
• Dynamically typed (no need to declare variable types).
• Supports Object-Oriented, Functional, and Procedural programming.
• Huge standard library and community support.
Python Syntax Basics
Comments
# This is a single-line comment
'''
This is a
multi-line comment
'''
Variables
name = "Alice"
age = 25
price = 19.99
Data Types
Type Example
int 5
float 5.5
str "Hello"
bool True / False
list [1, 2, 3]
tuple (1, 2, 3)
dict {"name": "Alice", "age": 25}
set {1, 2, 3}
Input and Output
name = input("Enter your name: ")
print("Hello", name)
Operators
Operator Example Meaning
+ a+b Addition
- a-b Subtraction
* a*b Multiplication
/ a/b Division
// a // b Floor Division
% a%b Modulus
** a ** b Exponentiation
== a == b Equals
!= a != b Not Equal
Conditional Statements
if age > 18:
print("Adult")
elif age == 18:
print("Just 18")
else:
print("Minor")
Loops
For Loop
for i in range(5):
print(i)
While Loop
count = 0
while count < 5:
print(count)
count += 1
Functions
def greet():
print("Hello!")
greet()
def add(a, b):
return a + b
print(add(5, 3))
Example Program
# Simple Calculator
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Sum is:", a + b)