📘 PAPER 2: OBJECT ORIENTED PROGRAMMING WITH PYTHON UNIT 4 – Dictionaries, Functions, File Handling & Regular Expressions (university of allahabad)
🔴 UNIT 4 – Dictionaries, Functions, File Handling & Regular Expressions
1️⃣ Dictionaries in Python
✅ Definition
A dictionary is an unordered collection of data stored as key–value pairs.
Example:
🔹 Characteristics
✔ Key-value based
✔ Mutable
✔ Keys must be unique
✔ Fast access
🔹 Accessing Dictionary Elements
🔹 Adding & Updating Values
🔹 Deleting Elements
2️⃣ Counting Frequency Using Dictionary
Example:
Output:
3️⃣ Python Functions
✅ Definition
A function is a block of reusable code.
🔹 Function Syntax
🔹 Types of Arguments
Example:
4️⃣ Passing Function as Argument
5️⃣ Lambda Function
Definition:
Anonymous function written in one line.
6️⃣ Map Function
7️⃣ List Comprehension
8️⃣ File Handling in Python
🔹 Opening a File
File Modes:
| Mode | Meaning |
|---|---|
| r | Read |
| w | Write |
| a | Append |
| r+ | Read + Write |
🔹 Reading File
🔹 Writing File
🔹 Closing File
9️⃣ String Processing
Common String Functions:
🔟 Regular Expressions (RegEx)
Definition:
Regular expressions are used for pattern matching.
Common Symbols
| Symbol | Meaning |
|---|---|
| . | Any character |
| ^ | Start of string |
| $ | End of string |
| * | Zero or more |
| + | One or more |
| [a-z] | Range |
Example:
Comments
Post a Comment