Unit 01. PWP (22616)
Unit 01. PWP (22616)
➢ Features of Python
Definition of Python:
• Python is a high-level, easy-to-learn programming language that supports multiple
programming styles, such as object-oriented, structured, and functional
programming.
Features of Python
1. Interactive
• Python supports interactive mode, allowing you to test and debug code in real-
time.
• You can execute a single line of code using the Python shell or IDLE.
Example:
Hello MSBTE!
Real-Life Use: Interactive mode helps while testing a small function in programs.
2. Object-Oriented
Example:
class Student:
self.name = name
s = Student("Rahul")
print(s.name)
Output: Rahul
Real-Life Use:
Object-oriented features are used in game development and banking systems.
3. Interpreted
• Python code is executed line by line by the Python interpreter, making debugging
easier.
Example:
x = 10
print(x * 5)
Real-Life Use:
Interpreted nature is useful for quick scripting tasks.
4. Platform Independent
Example:
Writing the same Python code on Windows and running it on Linux without changes.
Real-Life Use:
Used in web development and data analysis across various platforms.
Diagram
Advantages of Python
3. Efficient for real-world tasks like machine learning and web apps.
Disadvantages of Python
• Python programs are built using basic elements like identifiers, keywords,
indentation, variables, and comments. These elements define the structure and
readability of Python code.
1. Identifiers
• Definition:
Identifiers are the names used for variables, functions, and other programming
elements.
• Rules:
• Example:
2. Keywords
• Definition:
Keywords are reserved words in Python that have predefined meanings and cannot
be used as identifiers.
if True:
3. Indentation
• Definition:
Python uses indentation (spaces or tabs) to define the block of code, replacing {} or
other markers.
• Rules:
• Example:
if True:
• Common Error:
IndentationError occurs if it's inconsistent.
Example: IndentationError: unexpected indent.
4. Variables
• Definition:
Variables are containers to store data. In Python, variables are created when a value
is assigned.
• Rules:
• Example:
age = 25
print(age) # Output: 26
• Real-Life Use:
Used to store user inputs or program data.
5. Comments
• Definition:
Comments are lines that start with # and are ignored by the Python interpreter.
• Code Example:
'''This is a
multi-line comment'''
print("Hello MSBTE!")
• Real-Life Use:
Helps to explain the logic or mark TODOs in large programs.
Disadvantages
• Python environment setup includes the process of installing Python on your system
and using an IDE (Integrated Development Environment) to write, execute, and
debug Python programs easily.
1. Installation of Python
• Click on the Download button and choose the appropriate version for your operating
system (Windows, macOS, or Linux).
• Select the option "Add Python to PATH" (important for command-line usage).
• If Python is installed, it will display the installed version, e.g., Python 3.10.2.
2. Working of IDE
What is an IDE?
Diagram
• Installation:
Python Download ➔ Add to PATH ➔ Verification via python --version.
• IDE Usage:
Write Code ➔ Save File ➔ Execute Code ➔ View Output.
Disadvantages
1. Heavy Software: Some IDEs (e.g., PyCharm) require high system resources.
2. Dependency on Features: May reduce the ability to work with simple editors like
Notepad.
• A Python script is a file containing Python code that can be executed by the Python
interpreter.
• Scripts typically have the .py extension and are used to automate tasks or create
programs.
• You can use any text editor (e.g., Notepad, Visual Studio Code, or PyCharm) or the
built-in IDLE.
print("Welcome")
1. Using IDLE:
o Output:
Welcome
python welcome.py
o Output:
Welcome
Code Example
print("Welcome")
Diagram
Write Code (editor) ➔ Save as .py file ➔ Run Script (Terminal/IDE) ➔ View Output
Disadvantages
• Definition: Data types define the type of data a variable can store in Python.
• Python provides built-in data types to work with different kinds of data.
A. Numbers
• Types:
• Example:
x = 10 # Integer
y = 3.14 # Float
z = 2 + 3j # Complex
print(x, y, z)
B. String
• Definition: A collection of characters enclosed in single (' ') or double (" ") quotes.
• Characteristics:
• Example:
print(name)
print(name[0:3]) # Slicing
C. Tuples
• Features:
• Example:
D. Lists
• Features:
• Example:
print(colors)
E. Dictionary
• Features:
• Example:
Diagram
• Dynamic Typing: Python is a dynamically typed language, which means you don’t need to
declare the data type explicitly. The interpreter automatically determines the type of the
variable when you assign a value.
• Syntax:
variable_name = value
• Example:
x = 10 # Integer
y = 3.14 # Float
A. Numbers
B. String
C. Lists
D. Tuple
E. Dictionary
1. No explicit declaration:
x = 10 # Integer
❖ Summer 2022
2. List Data types used in python. Explain any two with example. (4marks)
❖ Winter 2022
❖ Summer 2023
❖ Winter 2023
❖ Summer 2024
3. List data types used in python. Explain any two with example. (4marks)
❖ Winter 2024