Introduction to Python
What is Python?
Python is a high-level, interpreted, general-purpose programming language.
It was created by Guido van Rossum and first released in 1991.
Python focuses on code readability and simplicity.
Why Python for AI & Data Science?
- Simple and easy to learn
- Huge ecosystem of libraries (NumPy, Pandas, Scikit-learn, TensorFlow, PyTorch…)
- Excellent community support
- Used by almost every company working in AI / Data Science
- Great for rapid prototyping
How Python Code Runs
Python is an interpreted language.
- You write the code in a
.pyfile or notebook - The Python interpreter reads the code line by line
- It converts it into machine-readable instructions
- The computer executes those instructions
You don’t need to compile Python code before running it.
Your First Python Program
print("Hello, World!")
Hello, World!
Congratulations! You have written and executed your first Python program.
Python is Case-Sensitive
Python treats uppercase and lowercase letters as different.
name = "Ravi"
print(name)
Ravi
Now try this (intentional error for learning):
print(Name)
NameError: name 'Name' is not defined
name and Name are two different variables in Python.
Another common mistake
Print("Hello")
NameError: name 'Print' is not defined
The correct function is print (all lowercase).
Indentation Matters
In many languages, indentation is only for readability. In Python, indentation is part of the syntax.
Python uses indentation (spaces or tabs) to define blocks of code.
Correct Example
if 10 > 5:
print("Ten is greater than five")
Ten is greater than five
Wrong Indentation (will cause error)
if 10 > 5:
print("Ten is greater than five")
IndentationError: expected an indented block
Always use 4 spaces for indentation (recommended). Most editors do this automatically when you press Tab.
Comments in Python
Comments are notes that you write for humans. Python completely ignores them.
Single-line Comment
Use the hash symbol #
# This is a comment
print("Hello") # This is also a comment
Hello
Why do we need comments?
- To explain why a piece of code exists
- To make the code easier to understand after months
- To temporarily disable code while testing
salary = 50000
# employees receive a 10% bonus on their basic salary
bonus = salary * 0.10
print(bonus)
5000.0
Good comments explain the “why”, not the “what”.
Statements in Python
A statement is a complete instruction that tells Python to do something.
Think of it like ordering food on Swiggy:
- You place an order → Restaurant receives it
- Chef prepares the food
- Delivery partner picks it up
- Food reaches your home
Each of these is a step (instruction). In programming, each such instruction is called a statement.
Examples of Statements
print("Order received")
age = 25
salary = 5000
salary = salary + 2000
Multi-line Statements
Sometimes one statement is too long. Python allows two ways:
1. Implicit (recommended) – using parentheses
total = (
100
+ 200
+ 300
+ 400
)
print(total)
1000
2. Explicit – using backslash \
total = 100 + 200 + \
300 + 400
print(total)
Prefer the parentheses method. It is cleaner and less error-prone.
Variables – Storing Values
A variable is like a labeled box where you store data.
name = "Kundan"
age = 25
city = "Hyderabad"
print(name)
print(age)
print(city)
Kundan 25 Hyderabad
Rules for Variable Names
- Can contain letters, numbers, and underscore (_)
- Cannot start with a number
- Cannot be a Python keyword (if, for, while, class…)
- Case-sensitive (age and Age are different)
Multiple Assignment
a = b = c = 30
print(a, b, c)
x, y, z = 10, 20, 30
print(x, y, z)
30 30 30 10 20 30
The print() Function
print() is one of the most used functions in Python.
Basic Usage
print("Hello")
print(100)
print(3.14)
Printing Multiple Values
name = "Ravi"
age = 28
print("Name:", name, "| Age:", age)
Name: Ravi | Age: 28
Using sep and end parameters
print("Python", "Java", "C++", sep=" | ")
print("Hello", end=" ")
print("World")
Python | Java | C++ Hello World
Common Beginner Mistakes
These mistakes are very common when you start. Making them is part of learning.
1. Forgetting quotes around strings
print(Hello)
NameError: name 'Hello' is not defined
2. Using = instead of == for comparison
(We will learn this properly later in if-conditions)
3. Mixing up variable names (case)
Newworld = "python"
print(newworld)
NameError: name 'newworld' is not defined
4. Using a keyword as variable name
if = 20
SyntaxError: invalid syntax
Don’t be afraid of errors. Read the error message carefully — it usually tells you exactly what went wrong.
What Next?
You have now completed the foundation of Python.
In the upcoming notebooks we will cover:
- Data Types in depth (int, float, str, bool, list, tuple, dict, set)
- Operators
- Conditional statements (if, elif, else)
- Loops (for, while)
- Functions
- Lambda, map, filter, reduce
- And much more…
Practice the examples from this introduction a few times. Speed will come naturally.
Introduction to Python
Start your Python journey here. This section covers the absolute basics before we move into deeper topics.
Select any topic from the left sidebar to begin.
Start Learning →
