Python – Module 1 Notes (Detailed &
Advanced)
Course: MCA 1st Year
Module: Introduction to Python – Basics, Data Types, Control Structures, Strings, Lists,
Tuples, Dictionaries, Functions
Introduction to Python
Introduction to Python
Python is a high-level, interpreted, general-purpose programming language.
Created by Guido van Rossum in 1991.
Known for its readability, simplicity, and extensive libraries.
Supports object-oriented, procedural, and functional programming paradigms.
Widely used in web development, data science, automation, AI/ML, etc.
Key Features:
• Interpreted → runs line by line.
• Dynamically typed → no need to declare data types.
• Automatic memory management (garbage collection).
• Rich standard library and third-party packages.
Python Versions:
• Python 2.x (deprecated)
• Python 3.x (current and recommended)
Setting up Python Path
Setting up Python Path
Installation:
1. Download from https://python.org.
2. Install and select Add Python to PATH.
Path Setup:
• Add Python’s directory to environment variables.
• Test by running "python --version" or "python3" in terminal/command prompt.
Python Data Types
Python Data Types
Numeric Types → int, float, complex
Sequence Types → str, list, tuple
Mapping Type → dict
Set Types → set, frozenset
Boolean Type → bool
Binary Types → bytes, bytearray, memoryview
Example:
x = 10 # int
y = 3.14 # float
z = 1 + 2j # complex
name = "Ujjwal" # string
flag = True # bool
Variables and Operators
Variables and Operators
Variables:
• Containers storing data.
• Dynamically typed → type inferred at runtime.
Example:
a=5
b = "Hello"
c = 3.14
id() Function: Returns the memory location of an object.
type() Function: Returns the type of a variable.
Operators:
• Arithmetic: +, -, *, /, //, %, **
• Comparison: ==, !=, >, <, >=, <=
• Logical: and, or, not
• Assignment: =, +=, -=, etc.
• Identity: is, is not
• Membership: in, not in
Control Structures
Control Structures
if-else statements for conditional logic.
elif for multiple conditions.
Nested if for complex decision-making.
Loops: for and while loops.
Iteration control: break, continue, and pass.
String Manipulation
String Manipulation
Accessing Strings via indexing and slicing.
Operations include concatenation, repetition, and membership testing.
Common methods: upper(), lower(), find(), replace(), len().
Lists
Lists
Lists are mutable ordered collections.
Support heterogeneous data types.
Common operations: append, insert, remove, sort, reverse.
List comprehension for concise construction.
Tuples
Tuples
Tuples are immutable ordered collections.
Operations include concatenation and repetition.
Functions like len(), max(), and min() are available.
Dictionaries
Dictionaries
Dictionaries store key-value pairs.
Keys are unique and immutable.
Methods include get(), keys(), values(), and items().
Functions
Functions
Functions are defined using def keyword.
Arguments can be positional, keyword, default, or arbitrary (*args, **kwargs).
Recursive functions are supported.
Variables have scopes: local and global.
Advanced Notes
Advanced Notes
Follow PEP 8 coding standards.
Use docstrings to document functions.
Handle errors using try-except blocks.
Write Pythonic code using list comprehensions and lambda functions.