Chapter 18m

Python Introduction

Learn Python programming from scratch. Explore Python history, features, applications, interpreter, installation, syntax, first program, and modern development practices.

This content is not yet available in dz. Showing English version.

View in English →

Python is a high-level, general-purpose programming language known for its simple syntax, readability, flexibility, and extensive ecosystem.

It was designed to make programming easier to learn, write, read, and maintain. Python allows developers to express complex programming ideas using relatively fewer lines of code.

Python is widely used in web development, automation, Artificial Intelligence (AI), Machine Learning (ML), Data Science, scientific computing, cybersecurity, and software development.

Python supports multiple programming paradigms, including:

  1. Procedural Programming
  2. Object-Oriented Programming (OOP)
  3. Functional Programming

Python is an interpreted language in the sense that its standard implementation executes programs through an interpreter and runtime environment. In CPython, source code is normally compiled into bytecode before execution by the Python Virtual Machine (PVM).

Python is open-source and maintained through the Python community under the guidance of the Python Software Foundation (PSF).

Learning Objectives

After completing this chapter, you will be able to:

  1. Understand what Python is and why it is used.
  2. Identify the important milestones in Python's history.
  3. Explain the major features and advantages of Python.
  4. Understand Python's programming paradigms.
  5. Identify real-world applications of Python.
  6. Understand the basic Python execution process.
  7. Differentiate between Python, an interpreter, and an implementation.
  8. Understand Python versions and compatibility.
  9. Identify common Python development tools.
  10. Install Python and execute your first program.
  11. Understand basic Python syntax, comments, and indentation.
  12. Use AI coding assistants responsibly while learning Python.

What Is Python?

Python is a high-level, general-purpose, dynamically typed programming language.

Let's understand these terms.

High-Level Language: Python provides human-readable syntax and hides many low-level hardware details. Programmers can focus more on solving problems than managing machine-level instructions.

General-Purpose Language: Python is not restricted to one particular application area. It can be used to build websites, automate tasks, analyze data, develop AI applications, and create software.

Dynamically Typed Language: Python determines the type of an object at runtime. You generally do not need to declare a variable's data type explicitly.

Example:

python
age = 25
name = "Rahul"
price = 99.50

print(type(age))
print(type(name))
print(type(price))

Expected Output:

text
<class 'int'>
<class 'str'>
<class 'float'>

In this example, Python identifies the types of the objects assigned to the variables.

Readable Syntax: Python uses indentation to organize code blocks and avoids unnecessary syntax in many common programming tasks.

History of Python

Python was created by Guido van Rossum. Its development started in December 1989 at Centrum Wiskunde & Informatica (CWI) in the Netherlands.

The first public release, Python 0.9.0, appeared in February 1991.

The name Python was inspired by the British comedy television series Monty Python's Flying Circus, not by the snake.

Python History – Version-Wise Timeline

Python VersionRelease Date
Python 0.9.0February 1991
Python 1.0January 1994
Python 1.5December 1997
Python 2.0October 2000
Python 2.7July 2010
Python 3.0December 2008
Python 3.1June 2009
Python 3.2February 2011
Python 3.3September 2012
Python 3.4March 2014
Python 3.5September 2015
Python 3.6December 2016
Python 3.7June 2018
Python 3.8October 2019
Python 3.9October 2020
Python 3.10October 2021
Python 3.11October 2022
Python 3.12October 2023
Python 3.13October 2024
Python 3.14October 2025
Python 3.15October 2026

Note: Python 2 and Python 3 are different major language generations. Python 2.7 was the final Python 2 release. Python 2 reached the end of its official support in January 2020. Modern development should use Python 3.

Why Learn Python?

Python is one of the most useful programming languages for beginners and professional developers.

Important reasons to learn Python include:

  1. Easy to Learn: Its readable syntax makes it suitable for beginners.
  2. Versatile: It supports different types of software development.
  3. Large Ecosystem: It provides extensive standard libraries and third-party packages.
  4. Automation: It can automate repetitive tasks and workflows.
  5. AI and Machine Learning: It has a rich ecosystem for modern AI development.
  6. Data Science: It provides tools for data analysis and visualization.
  7. Community Support: A large global community provides documentation, tutorials, and solutions.
  8. Cross-Platform Support: Python programs can run on different operating systems, subject to platform and dependency compatibility.
  9. Rapid Development: Developers can often build prototypes and applications quickly.
  10. Career Opportunities: Python skills are relevant to multiple software and technology careers.

Major Features of Python

Simple and Readable

Python syntax is designed to be readable.

Example:

text
print("Welcome to Python!")

The statement displays a message without requiring a class declaration or a complex entry-point structure.

High-Level

Python abstracts many low-level operations such as direct memory management in ordinary application code.

Dynamically Typed

Variables do not require explicit type declarations.

text
value = 100
value = "Python"

print(value)

Output:

text
Python

Python allows a variable name to refer to objects of different types at different times.

Object-Oriented

Python supports classes, objects, inheritance, encapsulation, and polymorphism.

Interpreted Execution Model

Python programs are executed using an implementation-specific runtime. In CPython, source code is compiled into bytecode and executed by the Python Virtual Machine.

Cross-Platform

Python is available for major operating systems, including Windows, macOS, and Linux.

Open-Source

Python is freely available, and its source code can be studied, modified, and redistributed according to its license.

Extensive Standard Library

Python includes built-in modules for file handling, mathematics, dates, JSON, networking, operating-system operations, and many other tasks.

Automatic Memory Management

Python manages object memory automatically. In CPython, reference counting and cyclic garbage collection are important parts of memory management.

Extensible

Python can work with components written in other programming languages, including C and C++.

Applications of Python

Python is used across many industries.

Application AreaCommon Uses
Web DevelopmentWebsites, APIs, backend systems
Artificial IntelligenceAI applications and intelligent systems
Machine LearningPredictive models and classification
Data ScienceData analysis and visualization
AutomationRepetitive tasks and workflow automation
Scientific ComputingMathematical and scientific research
CybersecuritySecurity testing and analysis tools
Desktop ApplicationsGUI-based software
Game DevelopmentGame prototypes and development tools
Cloud ComputingCloud automation and services
Internet of ThingsDevice automation and data processing
EducationProgramming fundamentals and computer science

Popular Python Libraries and Frameworks

Library / FrameworkPurpose
DjangoWeb development
FlaskLightweight web applications
FastAPIModern API development
NumPyNumerical computing
PandasData analysis
MatplotlibData visualization
Scikit-learnMachine Learning
PyTorchDeep Learning
TensorFlowMachine Learning and Deep Learning
PygameGame development
RequestsHTTP communication
SeleniumBrowser automation

These are third-party tools, not all part of Python's standard library.

How Python Works

To understand Python, it is useful to learn how a Python program moves from source code to execution.

The general process is:

  1. A programmer writes Python source code.
  2. The Python implementation reads and processes the source code.
  3. In CPython, source code is compiled into bytecode.
  4. The Python Virtual Machine executes the bytecode.
  5. The program produces results or interacts with the operating system and external resources.

Basic Python Execution Flow

Source Code → Compilation to Bytecode → Python Virtual Machine → Execution → Output

Important: This describes the usual CPython execution model. Other Python implementations may use different execution strategies.

What Is an Interpreter?

An interpreter is a software component that processes and executes programming instructions.

Python is commonly described as an interpreted language because developers normally execute programs through a Python runtime rather than manually compiling them into standalone machine-code executables.

What Is Bytecode?

Bytecode is an intermediate representation of a program. In CPython, it is executed by the Python Virtual Machine.

Python bytecode is not the same as native machine code.

What Is PVM?

PVM stands for Python Virtual Machine. It is the execution component responsible for running Python bytecode in CPython.

Python Implementations

Python is a language specification with multiple implementations.

The most commonly encountered implementations include:

  1. CPython: The standard and most widely used implementation, written primarily in C.
  2. PyPy: An alternative implementation known for its Just-In-Time (JIT) compilation technology.
  3. Jython: An implementation designed to run Python on the Java platform.
  4. IronPython: An implementation designed for the .NET ecosystem.
  5. MicroPython: A lightweight implementation for microcontrollers and resource-constrained environments.

Not every implementation supports every Python feature, library, or version in exactly the same way.

For most beginners, CPython is the recommended starting point.

Python Versions and Compatibility

Python follows a version-numbering system.

For example:

Python 3.15.2

  • 3 \= Major version
  • 15 \= Minor version
  • 2 \= Micro or patch version

Generally:

  • Major versions represent major language-generation changes.
  • Minor versions introduce new features and language improvements.
  • Micro versions primarily provide bug fixes and security updates.

Current Version Information

As of November 5, 2026, Python 3.15.2 is the latest stable Python release listed on the official Python release pages.

Python 3.14 and other maintained branches may also be appropriate depending on application compatibility and dependency requirements.

For this tutorial, examples use generally compatible Python 3 syntax unless a particular version-specific feature is explicitly identified.

Before choosing a Python version for a project, check:

  1. Library and framework compatibility.
  2. Operating-system support.
  3. Deployment environment.
  4. Security support status.
  5. Project requirements.

Python Development Environment

A development environment provides the tools needed to write, execute, test, and debug Python programs.

Python Interpreter

The interpreter executes Python programs.

Official website: https://www.python.org/

Code Editor

A code editor helps programmers write and manage source code.

Popular choices include:

  • Visual Studio Code
  • PyCharm
  • IDLE
  • Sublime Text

Terminal or Command Prompt

A terminal allows users to run Python programs and development commands.

Package Manager

pip is Python's commonly used package installer.

Example:

text
python -m pip install requests

This command installs the Requests package into the Python environment associated with the selected interpreter.

Virtual Environment

A virtual environment isolates project dependencies.

Create one using:

text
python -m venv .venv

Activate it on Windows:

text
.venv\Scripts\activate

Activate it on macOS or Linux:

text
source .venv/bin/activate

Virtual environments help prevent dependency conflicts between projects.

Installing Python

Follow these general steps:

  1. Visit https://www.python.org/downloads/
  2. Select a suitable Python release for your operating system.
  3. Download the installer or package.
  4. Follow the installation instructions.
  5. Open a terminal.
  6. Verify the installation.

Check the Python version:

text
python --version

On some systems, use:

text
python3 --version

Expected output example:

text
Python 3.15.2

The actual output depends on the installed version.

On Windows, enable the option to add Python to PATH when using an installer that provides that option.

Writing Your First Python Program

Now let's write our first Python program.

Example:

text
print("Hello, World!")

Expected Output:

text
Hello, World!

Explanation

  • print() is a built-in Python function.
  • Text inside quotation marks is a String literal.
  • The function displays the supplied value on the output stream.
  • Parentheses contain the function argument.

This is one of the simplest ways to verify that your Python environment is working.

Another Example

text
name = "Python"
print("Welcome to", name)

Expected Output:

text
Welcome to Python

Explanation:

  • name is a variable.
  • "Python" is a String value.
  • print() displays both supplied arguments separated by a space by default.

Basic Python Syntax

Syntax means the rules that determine how code must be written in a programming language.

Python has a relatively simple syntax, but correct indentation and statement structure are essential.

Statements

A statement is an instruction that Python can execute.

Example:

text
message = "Learning Python"
print(message)

Variables

Variables are names that refer to objects.

Example:

text
student_name = "Amit"
age = 20

print(student_name)
print(age)

Case Sensitivity

Python is case-sensitive.

Example:

text
name = "Amit"
Name = "Rahul"

print(name)
print(Name)

Output:

text
Amit
Rahul

Here, name and Name are two different identifiers.

Indentation

Indentation means the spaces at the beginning of a code line.

Python uses indentation to define code blocks.

Example:

python
age = 20

if age >= 18:
    print("You are an adult.")

Expected Output:

text
You are an adult.

The indented statement belongs to the if block.

Incorrect indentation can cause an IndentationError.

Comments

Comments are notes in source code that Python does not execute as ordinary program statements.

Single-line comment:

python
# This is a Python comment
print("Hello")

Multiline explanation using consecutive comments:

python
# Python is a programming language.
# It is widely used in software development.
print("Learning Python")

Python also supports multiline String literals using triple quotes. However, triple-quoted strings are not automatically comments; they create String objects and are commonly used for documentation strings (docstrings) in suitable contexts.

Python Programming Paradigms

A programming paradigm is an approach or style of writing programs.

Python supports multiple paradigms.

Procedural Programming

Procedural Programming organizes code around procedures or functions.

Example:

python
def greet():
    print("Hello!")

greet()

Output:

text
Hello!

Object-Oriented Programming

Object-Oriented Programming organizes programs around classes and objects.

Example:

python
class Student:
    def display(self):
        print("I am a student.")

student = Student()
student.display()

Output:

text
I am a student.

Functional Programming

Functional Programming emphasizes functions, expressions, and operations on data.

Example:

python
numbers = [1, 2, 3, 4]

squares = list(map(lambda x: x * x, numbers))

print(squares)

Output:

text
[1, 4, 9, 16]

Python supports these approaches, and developers can combine them where appropriate.

Python Compared with Other Programming Languages

FeaturePythonCJavaJavaScript
Language LevelHigh-LevelGenerally Low-LevelHigh-LevelHigh-Level
TypingDynamicStaticStaticDynamic
Common Execution ModelInterpreter and runtimeCompiledJVM-basedEngine-based
Memory ManagementAutomaticPrimarily manualAutomaticAutomatic
Main UsesAI, automation, web, dataSystems, embedded softwareEnterprise applicationsWeb development
Syntax StyleReadable and conciseMore explicitStructuredFlexible

These are general comparisons. Actual execution, performance, and memory behavior depend on the implementation and environment.

Python in Artificial Intelligence and Modern Development

Python plays an important role in modern software engineering and AI development.

It is frequently used for:

  • Generative AI applications.
  • Machine Learning models.
  • Natural Language Processing.
  • Computer Vision.
  • Data pipelines.
  • Automation systems.
  • API development.
  • AI-powered software tools.

Popular AI-related libraries and frameworks include PyTorch, TensorFlow, Transformers, and Scikit-learn.

Responsible Use of AI Coding Assistants

AI coding assistants can help programmers:

  1. Understand unfamiliar Python syntax.
  2. Generate example code.
  3. Explain error messages.
  4. Suggest improvements.
  5. Create test cases.
  6. Explore alternative solutions.

However, AI-generated code must always be reviewed and tested.

A useful prompt example:

"Write a Python program that checks whether a number is even or odd. Explain each line, include sample output, and identify possible edge cases."

Good development practice:

  • Understand the generated code before using it.
  • Verify syntax and expected behavior.
  • Test normal and edge cases.
  • Check security and dependency risks.
  • Avoid sharing passwords, API keys, or confidential information with AI tools.
  • Develop independent problem-solving skills.

AI should assist learning and development, not replace programming fundamentals.

Best Practices for Python Beginners

  1. Use meaningful variable and function names.
  2. Follow PEP 8 style guidelines.
  3. Use four spaces per indentation level.
  4. Keep functions focused on specific responsibilities.
  5. Write comments when they clarify why something is done.
  6. Use virtual environments for project dependencies.
  7. Prefer supported Python versions.
  8. Read error messages carefully.
  9. Test programs with different inputs.
  10. Use version control such as Git.
  11. Avoid unnecessary code complexity.
  12. Learn concepts instead of memorizing code.

Common Beginner Mistakes

MistakeExplanation
Incorrect IndentationPython uses indentation to identify blocks.
Incorrect CapitalizationPython identifiers are case-sensitive.
Missing QuotesString literals require appropriate quotation marks.
Missing ParenthesesFunction calls generally require parentheses.
Incorrect Variable NamesNames must follow Python identifier rules.
Using Python 2 SyntaxModern tutorials should use Python 3.
Ignoring Error MessagesErrors provide useful debugging information.
Dependency ConflictsProjects may require separate environments.

Example of incorrect indentation:

python
if True:
print("Hello")

This produces an IndentationError.

Correct version:

python
if True:
    print("Hello")

Knowledge Check

Answer the following questions to test your understanding.

  1. What is Python?
  2. Who created Python?
  3. In which year was Python first publicly released?
  4. Why was Python named Python?
  5. What does dynamically typed mean?
  6. What is the difference between Python 2 and Python 3?
  7. What is an interpreter?
  8. What is bytecode?
  9. What does PVM stand for?
  10. What is the purpose of pip?
  11. Why are virtual environments useful?
  12. What is indentation in Python?
  13. Name three major applications of Python.
  14. What is the difference between CPython and PyPy?
  15. Why should AI-generated Python code be tested?

Hands-On Exercises

Exercise 1: Write a Python program that displays:

python
Welcome to Python Programming!

Exercise 2: Create three variables representing your name, age, and city. Display all three values.

Exercise 3: Write a program that displays the following information:

python
Language: Python
Type: Programming Language
Level: High-Level

Exercise 4: Create a program using print() to display your learning goal.

Exercise 5: Create a Python program that calculates the sum of two numbers.

Exercise 6: Write a program that checks whether a number is even or odd.

Exercise 7: Create a program using an if statement and correct indentation.

Chapter Summary

In this chapter, you learned the fundamentals of Python.

Key points:

  • Python is a high-level, general-purpose programming language.
  • Guido van Rossum created Python.
  • Python was first publicly released in 1991.
  • Python supports procedural, object-oriented, and functional programming.
  • Python is widely used in web development, automation, AI, Machine Learning, and Data Science.
  • Python programs execute through a language implementation and runtime.
  • CPython commonly uses bytecode and the Python Virtual Machine.
  • Python has several implementations, including CPython, PyPy, and MicroPython.
  • Python supports automatic memory management.
  • Python uses indentation to define code blocks.
  • The print() function displays output.
  • Virtual environments help manage project dependencies.
  • AI tools can assist programming, but generated code must be verified.

What's Next?

Congratulations! You have completed Chapter 1: Python Introduction.

In the next chapter, you will learn how to install Python, configure your development environment, use the Python interpreter, and run Python programs in different ways.

Next Chapter: Python Installation and Setup

Example

python
# Your first Python programprint("Hello, World!")print("Welcome to w3primecode")