Module – 02
Daily Topics Covered
Python
Features of python
Installation of Python
Running Python Programme
. Python Syntax and Indentation
Variables and Data Types
Ques – What Is Python ?
Python is an open-source, object-oriented, and interpreted
programming language that emphasizes code readability and ease of
use. It supports multiple programming paradigms — procedural,
object-oriented, and functional programming.
Or
Python is a high-level, interpreted, and general-purpose
programming language known for its simplicity and readability. It was
created by Guido van Rossum and first released in 1991.
Ques - Key Features of Python ?
Feature Description
Simple & Easy to Python has a clean, English-like syntax,
Learn which makes it beginner-friendly.
Feature Description
You don’t need to compile Python code;
Interpreted
it’s executed line by line by the
Language
interpreter.
Freely available for everyone to use and
Open Source
modify.
Runs on Windows, macOS, Linux, and
Cross-Platform
other systems.
Supports classes, objects, and
Object-Oriented
inheritance.
Comes with a large standard library and
supports thousands of third-party
Extensive Libraries
modules (like NumPy, Pandas,
TensorFlow, etc.).
No need to declare variable types
Dynamic Typing
explicitly; types are inferred at runtime.
Automatic
Memory Garbage collection is built-in.
Management
Ques - Uses of Python?
Domain Applications
Web Development Django, Flask, FastAPI
Data Science & Machine NumPy, Pandas, Scikit-learn,
Learning TensorFlow
Automation & Scripting Task automation, system scripts
Game Development Pygame
Artificial Intelligence NLP, Deep Learning
Desktop Applications Tkinter, PyQt
Network scanning, penetration
Cybersecurity
testing
IoT & Robotics Raspberry Pi programming
Installation of Python:
Steps:
1. Visit [Link]
2. Download the latest version (3.x).
3. During installation, check ✅ "Add Python to
PATH".
4. Verify installation:
python3 –version
Running Python
Programs
Once Python is installed, you
can run Python code in
several ways
— using IDLE, VS Code, Jupyter Notebook, or the Command
Line
1. Using IDLE (Python’s Built-in Editor)
IDLE stands for Integrated Development and Learning
Environment.
It is automatically installed with Python.
Steps:
5. Open IDLE (search for IDLE in the Start menu).
6. You’ll see the Python shell — a prompt like this:
Type your code directly:
print("Hello, Python!")
Press Enter — it executes immediately.
1. To run a saved script:
o
Click File → New File
o
Type your program:
o
print("Welcome to Python!")
o
Save it as [Link]
o
Press F5 or click Run → Run Module
2. Using Visual Studio Code (VS Code)
VS Code is a popular editor for
Python development.
✅ Steps:
1. Install VS Code.
2. Install the Python Extension from the Extensions
Marketplace.
3. Open your folder and create file — e.g.,
a [Link].
4. Write your code:
print("Running Python in VS
Code") Run it by:
5. Clicking ▶️“Run Python File”
6. pressing Ctrl + F5
7. using the terminal:
python
[Link]
Python Syntax & Indentation
Python’s syntax is designed to be simple, clean, and
readable, similar to plain English.
Unlike many programming languages, Python uses
indentation (spaces) to define code blocks — not curly
braces {} or keywords.
print("Hello, World!")
Explanation:
print() is a built-in function.
Statements don’t need a semicolon ; at the end.
Python code runs top to bottom.
Indentation in Python
Indentation means spaces at the beginning of a line.
Python uses indentation to define the scope of loops, functions,
and conditionals.
If indentation is incorrect, Python will show an Indentation Error.
Example (Correct Indentation):
if 5 > 2:
print("Five is greater than two!")
Output:
Five is greater than two!
Python Comments and Docstrings
Python allows you to add comments and
documentation strings (docstrings) to explain your
code.
They don’t affect program execution — they’re
ignored by the Python interpreter.
1. Comments in Python
Definition:
A comment is a piece of text in your program that is meant
for humans, not for the computer.
It helps you or others understand what the code does.
Types of Comments
(A) Single-Line Comment:
starts with a hash symbol (#).
Everything after # on that line is ignored by Python.
#This is a single-line comment
print("Hello, Python!")
# This prints a message
Output:
Hello, Python!
(B) Multi-Line Comment
Python doesn’t have a special syntax for multi-line comments
like /* ... */ in C.
Instead, you can use:
1. Multiple # lines, or
2. A triple-quoted string (''' ... ''' or """ ... """) not assigned to a
variable.
Example:
# This is line 1 of the comment
# This is line 2 of the comment
# This is line 3 of the comment
Docstrings
(Documentation
Strings)
🔹 Definition:
A docstring is a special
type of comment used to
document functions, classes, or modules.
It tells what the function or class does.
Docstrings are written using triple quotes
(""" ... """).
Examples:
def add(a, b):
"""This function returns the sum of two numbers."""
return a + b
print(add(5, 3))
output:
8
Example:
Docstring for Class
class Student:
"""This class represents a student with name and age."""
def init (self, name, age):
[Link] = name
[Link] = age
Access the
docstring::-
print(Student. doc
)
Output:
This class represents a
student with name and
age.
Variables :
Ques - What is a
Variable?
Ans : - A variable in Python is a named location in memory
used to store data (a value) that can be changed or updated
during program execution.
👉 In simple words:
A variable is like a container that holds some value.
Creating a Variable
In Python, you don’t need to declare the data type explicitly.
You just assign a value using the assignment operator (=).
x = 10 # integer
name = "Python" # string
pi = 3.14 # float
is_fun = True #
Boolean
Explanation:
x is assigned integer 10
name holds a string
"Python"
pi stores a float value
is_fun is a boolean
(True / False)
Feature Description Example
Features of You can directly assign a
1. No need for
Variables: value without declaring its x = 5
declaration
type.
Type is decided at runtime, x = 5, then x =
2. Dynamic Typing
not at compile time. "Hello" (valid)
Name and name are Name = "A"; name
3. Case-sensitive
different variables. = "B"
Variables can point to Lists are mutable;
4. Mutable /
mutable or immutable strings are
Immutable
objects. immutable.
Feature Description Example
Variables store references
5. Object reference (addresses) to objects, not a = [1, 2, 3]; b = a
the actual data.
6. Reassignment You can reassign a variable x = 10; x =
allowed to a new value or type. "Python"
7. Memory Python handles memory
No manual freeing
managed allocation and garbage needed
automatically collection.
8. Multiple Assign multiple variables
a, b, c = 1, 2, 3
assignment in one line.
Data Types:
In Python, data types define the kind of value a
variable holds.
Python is dynamically typed, meaning you don’t need to
declare the type — it’s automatically assigned when you
assign a value.
Integer (int):
Definition:
Represents whole numbers (positive, negative, or
zero).
No decimal point.
a = 10
b = -25
c=0
print(type(a)) # <class 'int'>
Key Points:
Integers can be of any length (limited by memory).
Used for counting, indexing, and arithmetic.
. Floating-Point (float)
Definition:
Represents real numbers with decimal points or
exponents.
Examples:
x = 3.14
y = -0.5
z = 2e3 # 2 × 10³ = 2000.0
print(type(x)) # <class 'float'>
Key Points:
Used for mathematical and scientific calculations.
Floating-point numbers may lose precision slightly (e.g., 0.1 +
0.2 ≠ 0.3 exactly).
3. String (str)
Definition:
Sequence of characters enclosed in single, double, or triple
quotes.
Strings are immutable (cannot be changed after creation).
Examples: name
= "Python" msg =
'Hello World' para =
"""This is
a multiline string"""
print(type(name)) # <class 'str'>
Examples
print(name[0]) # P (indexing)
print(name[0:3]) # Pyt (slicing)
print([Link]()) # PYTHON
print([Link]()) # python
print(len(name)) #6
4. Boolean (bool)
Definition:
Represents truth
values: True or
False.
Internally, True =
1 and False = 0.
Example:
x = True
y = False
print(typ # <class 'bool'>
e(x))
# True
print(5 >
3) # False
print(10
== 20)
Commonly used in conditional statements and
Key logical operations.
Points:
[Link]
(complex) Definition:
Represents
complex
numbers with a
real and
imaginary part.
Syntax: a + bj
(where j = √-1)
Examples:
print(type(c1)) # <class 'complex'>
c1 = 2 + 3j
print([Link]) # 2.0
c2 = 5 - 2j
print([Link]) # 3.0
Key Points:
Useful in advanced mathematics, engineering, and
signal processing.
Supports addition, subtraction, multiplication, etc.
print(c1 + c2) # (7+1j)
print(c1 * c2) # (16+11j)