Introduction UNIT
& Programming
1 with
ESP8266
Introduction to Python
Prof. Sheekha Raina
Assistant Professor
AI&ML Department
Content
1. Introduction…………………………………………4
2. History and features of Python……….…….7
3. Installation and execution environment.26
4. Python syntax and semantics……………...27
5. Variables, identifiers, keywords…………..36
6. Input/output functions and Type
conversions …………………..……………………….40
7. Data types ……….………………………...........43
8. Operators and expressions………………....69
Introduction
Python is a widely used programming language developed by Guido van
Rossum and first released in 1991.
It is commonly applied in areas such as:
• Web development (server-side)
• Software development
• Mathematical computing
• System scripting
Web Development (Server-side):
Python is used to build the backend of websites and web applications.
Frameworks like Django and Flask help developers handle tasks such
as database management, user authentication, and server logic
efficiently.
Introduction
Software Development:
Python is used to create desktop and standalone software applications. It
supports rapid development and testing, making it suitable for building
reliable and scalable software solutions.
Mathematical Computing:
Python is widely used for mathematical calculations, data analysis, and
scientific research. Libraries such as NumPy, Pandas, and SciPy help
perform complex mathematical operations and data processing.
System Scripting:
Python is used to automate system-related tasks like file handling, process
management, and task scheduling. It helps system administrators save
time by automating repetitive operations.
Key Features of Python Programming Language
Python is a cross-platform programming language that works on Windows,
macOS, Linux, Raspberry Pi, and other systems.
It has a simple and easy-to-understand syntax that is similar to the English
language.
Python allows developers to write programs using fewer lines of code
compared to many other programming languages.
Python is an interpreted language, so code can be executed immediately,
making prototyping fast and efficient.
Python supports multiple programming paradigms, including procedural,
object-oriented, and functional programming.
History of Programming Language
Year/Period Event Description
Late 1980s Guido van Rossum started developing Python at CWI
(Netherlands) with the goal of creating a simple and readable
language.
1991 Python was officially released for the first time. The name was
inspired by Monty Python’s Flying Circus.
2000 Python 2.0 was released, introducing features like list
comprehensions, garbage collection, and Unicode support.
2008 Python 3.0 was released with significant improvements in
design, readability, and Unicode support; however, it was not
backward-compatible with Python 2.
2010–2020 Python’s popularity increased rapidly in web development, data
science, AI, and automation.
History of Programming Language
Year/Period Event Description
Between 2010 and 2020, several Python 3 versions were
launched, including:
Python 3.1 – 3.8
2020 Python 2 reached End of Life in 2020, making Python 3 the
standard version.
Present Python continues to evolve with regular updates and is one of
the most widely used programming languages worldwide. As of
December 2025, the latest stable version of Python is:
Python 3.14.2, released on December 5, 2025.
This version includes recent bug fixes and improvements and is
the most up-to-date production release available.
Installation and execution environment:
Follow these steps to set up the Python programming environment on your system:
1. Download Python
Visit the official Python website: [Link]
Download the latest stable version of Python suitable for your operating system
(Windows, macOS, or Linux).
Python Environment Setup
2. Install Python
Run the installer file.
Important (Windows): Check the option “Add Python to PATH” before clicking
Install Now.
Complete the installation by following the on-screen instructions.
Python Environment Setup
After initiating the installation process, the setup window will appear
as shown below.
Python Environment Setup
After the successful completion of the setup process, the success
window will appear as shown below.
Python Environment Setup
3. Verify Installation
Open Command Prompt (Windows) or Terminal (macOS/Linux).
Type python --version or python3 --version and press Enter.
If Python is installed correctly, the installed version number will be displayed as
shown below:
Python Environment Setup
4. Python Interpreter
Python runs using an interpreter, which executes code line by line.
You can start the interpreter by typing python in the command prompt or terminal.
5. Choose an IDE or Code Editor (Optional)
Commonly used IDEs/editors include:
1. Pycharm
2. IDLE
3. Visual Studio Code
4. Replit
5. Sublime Text
6. Spyder
7. PvDev
8. Jupyter
9. Thonny
[Link]
Python Environment Setup
These tools make writing and running Python programs easier.
Python IDE- IDLE
IDLE (Integrated Development and Learning Environment) is a dedicated platform
or software to develop Python applications. It is a full-fledged editor that is used
to create, modify, and execute python code. It can also be used like the Python
Shell to execute single statements. Python IDLE would be of great help, especially
to beginners.
IDLE is open-sourced and available free of charge.
Key Features
Interactive Shell: IDLE’s interactive shell allows you to execute Python code one
statement at a time, making it a great learning tool.
Simple Debugger: Provides basic debugging capabilities such as stepping through
code and inspecting variables.
Auto-Completion: A basic auto-completion feature helps you avoid syntax errors as
you write.
Python Environment Setup
Steps to open IDLE environment:
1. Click on the Start button and search for the IDLE application that is already
installed. (Refer to slide no. 7 to 12)
Python Environment Setup
Steps to open IDLE environment:
2. Click on this application
3. The following Shell window will appear:
Python Environment Setup
Steps to open IDLE environment:
3. The window displays the execution of a program to sum two numbers. This
Python shell window is known as Interactive Mode.
Python Environment Setup
1. In the Interactive mode, click the File>New File, untitled window will open as
shown below: It refers to as the script mode.
Python Environment Setup
Write the program to do the addition of two numbers. Click on Run>Run Module to
execute the code.
Python Environment Setup
Python Environment Setup
When we click on Run Module, the following dialog box will appear as shown
below:
Python Environment Setup
Click on the Ok button. The following dialog box will appear as shown below:
Give the file name with .py extension i.e. optional and click on Save button.
Python Environment Setup
The output will be displayed in an interactive mode as shown below: This way we
can write a program in an interactive mode and script mode.
Python Environment Setup
Step-by-step methods to open Python from the Command Prompt (CMD) on
Windows operating system:
1. Press Win + R, the Run dialog box will open.
2. Type cmd and press Enter.
Python Environment Setup
The command prompt window will open as shown below:
Python Environment Setup
In the Command Prompt, type: python
Press enter.
The python prompt will be displayed. Now you can perform the addition of two
numbers as shown below:
Python syntax and semantics
Python syntax is like grammar for this programming language. Syntax refers to the
set of rules that defines how to write and organize code so that the Python
interpreter can understand and run it correctly. These rules ensure that your code
is structured, formatted, and error-free. Here are some basic Python syntax:
Indentation in Python
Python Indentation refers to the use of whitespace (spaces or tabs) at the
beginning of code line. It is used to define the code blocks. Indentation is crucial in
Python because, unlike many other programming languages that use braces "{}" to
define blocks, Python uses indentation. It improves the readability of Python code,
but on other hand it became difficult to rectify indentation errors. Even one extra
or less space can leads to indentation error. E.g.
if 10 > 5:
print("This is true!")
print("I am tab indentation")
print("I have no indentation")
Variables in Python
Variables are used to store data values. In Python, there is no need to declare a variable
explicitly. A variable is created automatically when a value is assigned to it.
In Python, variables do not have a fixed data type. The type is assigned automatically
and can change later in the program.
Type Casting:
Type Casting in Python refers to the process of converting a variable from one data type to
another in order to specify its data type.
How to get the type of a variable?
You can find the data type of a variable by using the type() function.
Usage of Single or Double Quotes with variables?
Variables are case sensitive
Variable names in Python are case-sensitive; for example, count and
Count are treated as different variables.
Identifiers in Python:
Identifiers are the names used to identify variables, functions,
classes, modules, or other objects in Python.
Rules for Identifiers in Python:
[Link] identifier must start with a letter (a–z or A–Z) or an underscore
(_).
[Link] cannot start with a digit.
[Link] can contain letters, digits, and underscores only.
[Link] characters like @, #, $, % are not allowed.
[Link] (such as if, for, while, class, etc.) cannot be used as
identifiers.
[Link] are case-sensitive (total, Total, and TOTAL are different).
[Link] can be of any length.
Keywords in Python:
Keywords in Python are reserved words that have predefined
meanings and cannot be used as identifiers.
How to verify keywords in Python?
Line 1: import keyword
•This imports the built-in keyword module in Python.
•The keyword module provides information about Python’s
reserved keywords.
Line 2: print([Link])
•kwlist is a predefined list inside the keyword module.
•It contains all the Python keywords of the currently installed
Python version.
• print() displays this list on the screen.
Comments in Python
Comments in Python are statements written within the code. They are meant to
explain, clarify, or give context about specific parts of the code. The purpose of
comments is to explain the working of a code, they have no impact on the
execution or outcome of a program.
Single Line Comment
Single line comments are preceded by the "#" symbol. Everything after this symbol
on the same line is considered a comment.
For Example:
first_name = "Reddy"
last_name = "Anna" # assign last name
# print full name
print(first_name, last_name)
Output
Reddy Anna
Multi-line Comment
Python doesn't have a specific syntax for multi-line comments. However, programmers often
use multiple single-line comments, one after the other, or sometimes triple quotes (either '''
or """), even though they're technically string literals. Below is the example of multiline
comment.
'''
Multi Line comment.
Code will print name.
'''
f_name = "Alen"
print(f_name)
Continuation of Statements in Python
In Python, statements are typically written on a single line. However, there are scenarios
where writing a statement on multiple lines can improve readability or is required due to the
length of the statement. This continuation of statements over multiple lines is supported in
Python in various ways:
Implicit Continuation
Python implicitly supports line continuation within parentheses (), square brackets [], and
curly braces {}. This is often used in defining multi-line lists, tuples, dictionaries, or function
arguments.
# Line continuation within square brackets '[]'
numbers = [
1, 2, 3,
4, 5, 6,
7, 8, 9
]
print(numbers)
Explicit Continuation
You can use backslash '\' to indicate that a statement should continue on the next line.
# Explicit continuation
s = "GFG is computer science portal " \
"by Geeks, used by Geeks."
print(s)
Note: Using a backslash does have some pitfalls, such as if there's a space after the
backslash, it will result in a syntax error.
Input and Output Function:
Understanding input and output operations is fundamental to Python
programming. With the print() function, we can display output in various
formats, while the input() function enables interaction with users by
gathering input during program execution.
Taking input in Python
Python's input() function is used to take user input. By default, it returns the
user input in form of a string.
Example:
name = input("Enter your name: ")
print("Hello,", name, "! Welcome!")
Output
Enter your name: GeeksforGeeks
Hello, GeeksforGeeks ! Welcome!
Printing Output using print() in Python:
Print() function allows us to display text, variables and expressions on the
console. Let's begin with the basic usage of the print() function:
In this example, "Hello, World!" is a string literal enclosed within double
quotes. When executed, this statement will output the text to the console.
print("Hello, World!")
Output
Hello, World!
Data Types in Python:
Data types specify the type of data that a variable can store.
Python is a dynamically typed language, so the data type of a
variable is determined at runtime.
By default, Python has various built-in data types organized
under the following categories.
Text Type: str
Numeric Types: int, float, complex
Sequence Types: list, tuple, range
Mapping Type: dict
Set Types: set, frozenset
Boolean Type: bool
Binary Types: bytes, bytearray, memoryview
None Type: NoneType
Example:
Python Operators:
Python operators are special symbols or keywords used to
perform operations on variables and values.
Python divides the operators in the following groups:
1. Arithmetic operators
2. Assignment operators
3. Comparison operators
4. Logical operators
5. Identity operators
6. Membership operators
7. Bitwise operators
Python Operators:
1. Arithmetic operators: Arithmetic operators are used with numeric
values to perform common mathematical operations:
Example of Arithmetic operators
2. Assignment Operators: Assignment operators are used to
assign values to variables and, in some cases, perform an
operation and assign the result to the same variable.
Example:
Example of Assignment Operators:
3. Comparison Operators
Comparison operators are used to compare two values. They
return True or False based on the comparison result.
Example of Comparison Operators:
4. Logical Operators: Logical operators are used to combine
conditional statements and return a Boolean value (True or False).
Example of Logical Operators:
5. Identity Operators: These operators are used to compare
objects, not whether they have the same value, but whether they
refer to the same object in memory (same memory location)
Example of Identity Operators:
6. Membership Operators: These operators are used to test
whether a value is present in a sequence or not.
They return True or False.
Example of Membership Operators:
7. Bitwise Operators: Bitwise operators are used to perform
operations on numbers at the binary (bit-by-bit) level.
They work directly on the binary representation of integers.
Example of Bitwise Operators:
Expressions in Python:
An expression is a combination of operators and operands that is interpreted
to produce some other value. In any programming language, an expression is
evaluated as per the precedence of its operators. So that if there is more than
one operator in an expression, their precedence decides which operation will
be performed first. We have many different types of expressions in Python.
Let's discuss all types along with some exemplar codes :
1. Constant Expressions: These are the expressions that have constant values
only.
2. Arithmetic Expressions: An arithmetic expression is a combination of
numeric values, operators, and sometimes parenthesis. The result of this type of
expression is also a numeric value.
3. Integral Expressions: These are the kind of expressions that produce
only integer results after all computations and type conversions.
4. Floating Expressions: These are the kind of expressions which produce
floating point numbers as result after all computations and type conversions.
5. Relational Expressions: In these types of expressions, arithmetic
expressions are written on both sides of relational operator (> , < , >= , <=).
Those arithmetic expressions are evaluated first, and then compared as per
relational operator and produce a boolean output in the end. These expressions
are also called Boolean expressions.
6. Logical Expressions: These are kinds of expressions that result in
either True or False. It basically specifies one or more conditions
7. Bitwise Expressions: These are the kind of expressions in which
computations are performed at bit level.
8. Combinational Expressions: We can also use different types of
expressions in a single expression, and that will be termed as combinational
expressions.
Operator Precedence
Operator precedence
describes the order in
which operations are
performed.
Operator Precedence