Master the fundamentals of Python programming including syntax, variables, data types, operators, input/output, and type conversion. Perfect for beginners to start coding confidently.
1. Introduction to Python
Python is a high-level, interpreted, and general-purpose programming language. It is known for its simplicity, readability, and large community support.
Key Features:
- Easy to learn and read
- Interpreted and dynamically typed
- Supports multiple paradigms: procedural, object-oriented, functional
- Extensive standard library and third-party packages
Example:
print("Welcome to Python!")
2. Installing Python & IDE Setup
- Installation: Download Python from python.org and install it.
- IDE Setup:
- VS Code: Lightweight, customizable, supports Python extension
- PyCharm: Professional IDE with advanced features for Python
- Jupyter Notebook: Best for data science, allows code execution with Markdown notes
Example: Check Python installation:
python --version
3. Python Syntax, Comments, and Indentation
- Python uses indentation to define blocks of code.
- Comments are written using
#for single-line or""" """for multi-line.
Example:
# This is a single-line comment
"""
This is a
multi-line comment
"""
if True:
print("Python uses indentation instead of braces")
4. Variables & Data Types
Variables store values in memory and do not require explicit declaration.
Common Data Types:
int– Integer numbersfloat– Decimal numbersstr– Text stringsbool– True or FalseNone– Represents no value
Example:
age = 25 # int
price = 99.99 # float
name = "Chinmaya" # str
is_active = True # bool
data = None # NoneType
print(age, price, name, is_active, data)
5. Basic Operators
Operators allow performing arithmetic, comparison, and logical operations.
Arithmetic Operators:
a = 10
b = 3
print(a + b) # 13
print(a - b) # 7
print(a * b) # 30
print(a / b) # 3.3333
print(a % b) # 1
print(a ** b) # 1000
print(a // b) # 3
Comparison Operators:
print(a == b) # False
print(a != b) # True
print(a > b) # True
print(a < b) # False
print(a >= b) # True
print(a <= b) # False
6. Input/Output
Python allows interaction with users via input() and outputs with print().
Example:
name = input("Enter your name: ")
age = int(input("Enter your age: "))
print(f"Hello {name}, you are {age} years old.")
7. Type Conversion
Convert one data type into another using built-in functions:
Example:
num_str = "10"
num_int = int(num_str) # Convert string to integer
num_float = float(num_str) # Convert string to float
num_str_again = str(123) # Convert number to string
print(num_int + 5) # 15
print(num_float + 2.5) # 12.5
print(num_str_again + "4") # "1234"