Python Foundation

Introduction to Python

01 · What is Python? Introduction · 1 of 12

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.

02 · Why Python for AI & Data Science? Introduction · 2 of 12

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
03 · How Python Code Runs Introduction · 3 of 12

How Python Code Runs

Python is an interpreted language.

  1. You write the code in a .py file or notebook
  2. The Python interpreter reads the code line by line
  3. It converts it into machine-readable instructions
  4. The computer executes those instructions

You don’t need to compile Python code before running it.

04 · Your First Program Introduction · 4 of 12

Your First Python Program

Python
print("Hello, World!")
Output
Hello, World!

Congratulations! You have written and executed your first Python program.

05 · Python is Case-Sensitive Introduction · 5 of 12

Python is Case-Sensitive

Python treats uppercase and lowercase letters as different.

Python
name = "Ravi"
print(name)
Output
Ravi

Now try this (intentional error for learning):

Python
print(Name)
Error
NameError: name 'Name' is not defined

name and Name are two different variables in Python.

Another common mistake

Python
Print("Hello")
Error
NameError: name 'Print' is not defined

The correct function is print (all lowercase).

06 · Indentation Matters Introduction · 6 of 12

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

Python
if 10 > 5:
    print("Ten is greater than five")
Output
Ten is greater than five

Wrong Indentation (will cause error)

Python
if 10 > 5:
print("Ten is greater than five")
Error
IndentationError: expected an indented block

Always use 4 spaces for indentation (recommended). Most editors do this automatically when you press Tab.

07 · Comments in Python Introduction · 7 of 12

Comments in Python

Comments are notes that you write for humans. Python completely ignores them.

Single-line Comment

Use the hash symbol #

Python
# This is a comment
print("Hello")  # This is also a comment
Output
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
Python
salary = 50000
# employees receive a 10% bonus on their basic salary
bonus = salary * 0.10
print(bonus)
Output
5000.0

Good comments explain the “why”, not the “what”.

08 · Statements in Python Introduction · 8 of 12

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

Python
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

Python
total = (
    100
    + 200
    + 300
    + 400
)
print(total)
Output
1000

2. Explicit – using backslash \

Python
total = 100 + 200 + \
        300 + 400
print(total)

Prefer the parentheses method. It is cleaner and less error-prone.

09 · Variables – Storing Values Introduction · 9 of 12

Variables – Storing Values

A variable is like a labeled box where you store data.

Python
name = "Kundan"
age = 25
city = "Hyderabad"
print(name)
print(age)
print(city)
Output
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

Python
a = b = c = 30
print(a, b, c)

x, y, z = 10, 20, 30
print(x, y, z)
Output
30 30 30
10 20 30
10 · The print() Function Introduction · 10 of 12

The print() Function

print() is one of the most used functions in Python.

Basic Usage

Python
print("Hello")
print(100)
print(3.14)

Printing Multiple Values

Python
name = "Ravi"
age = 28
print("Name:", name, "| Age:", age)
Output
Name: Ravi | Age: 28

Using sep and end parameters

Python
print("Python", "Java", "C++", sep=" | ")
print("Hello", end=" ")
print("World")
Output
Python | Java | C++
Hello World
11 · Common Beginner Mistakes Introduction · 11 of 12

Common Beginner Mistakes

These mistakes are very common when you start. Making them is part of learning.

1. Forgetting quotes around strings

Python
print(Hello)
Error
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)

Python
Newworld = "python"
print(newworld)
Error
NameError: name 'newworld' is not defined

4. Using a keyword as variable name

Python
if = 20
Error
SyntaxError: invalid syntax

Don’t be afraid of errors. Read the error message carefully — it usually tells you exactly what went wrong.

12 · What Next? Introduction · 12 of 12

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.

Home Introduction to Python

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 →