PYTHON PROGRAMMING – FULL EXAM NOTES (SEMESTER 5)
------------------------------------------
1. INTRODUCTION TO PYTHON
------------------------------------------
• Python is a high-level, interpreted, general-purpose programming language.
• Features:
- Simple and easy to learn.
- Portable and platform-independent.
- Object-oriented.
- Large standard library.
• Applications: Web development, AI, Machine Learning, Data Analytics, Scripting.
------------------------------------------
2. PYTHON BASICS
------------------------------------------
• Indentation:
- Python uses indentation to define code blocks.
- Example:
if x > 0:
print("Positive")
• Variables:
- No need to declare type.
- Example: x = 10
• Comments:
- Single-line: #
- Multi-line: ''' ''' or
• Keywords:
- Examples: if, for, while, break, continue, return, try, except.
------------------------------------------
3. DATA TYPES
------------------------------------------
• Basic Types:
- int, float, str, bool, complex.
• Sequence Types:
- list, tuple, range.
• Mapping Type:
- dict
• Set Types:
- set, frozenset
• Conversion Functions:
- int(), float(), str(), list(), tuple(), set()
------------------------------------------
4. STRINGS
------------------------------------------
• Strings are immutable.
• Indexing:
- Forward: 0, 1, 2…
- Backward: -1, -2, -3…
• Slicing:
- s[start:end:step]
- Example: s[1:4]
• Useful Functions:
- lower(), upper(), isalpha(), isdigit(), replace(), split(), join()
------------------------------------------
5. LISTS
------------------------------------------
• Ordered, mutable.
• Creation: list1 = [10, 20, 30]
• Methods:
- append(), extend(), insert()
- remove(), pop(), clear()
- sort(), reverse()
• Slicing works same as strings.
------------------------------------------
6. TUPLES
------------------------------------------
• Ordered and immutable.
• Functions:
- tuple(), count(), index()
• Example:
t = (10, 20, 30)
------------------------------------------
7. DICTIONARIES
------------------------------------------
• Key-value pairs.
• Example:
d = {'A': 10, 'B': 20}
• Methods:
- keys(), values(), items(), update(), get(), pop(), clear()
------------------------------------------
8. SETS
------------------------------------------
• Unordered collection of unique elements.
• Methods:
- add(), update(), remove(), discard()
• Operations:
- union(), intersection(), difference(), symmetric_difference()
------------------------------------------
9. CONTROL STATEMENTS
------------------------------------------
• if, elif, else
• loops: for, while
• break: exit loop
• continue: skip iteration
• pass: placeholder
Example:
for i in range(5):
if i == 2:
continue
print(i)
------------------------------------------
10. FUNCTIONS
------------------------------------------
• Defined using def.
• Types of Arguments:
- Required
- Default
- Keyword
- Variable-length (*args, **kwargs)
• Lambda Functions:
- Anonymous functions
- Example:
f = lambda x: x + 5
------------------------------------------
11. MODULES & PACKAGES
------------------------------------------
• Module: Python file containing code.
• Package: Folder containing modules + __init__.py
------------------------------------------
12. FILE HANDLING
------------------------------------------
• Modes:
- r, w, a, rb, wb
• Functions:
- read(), readline(), write(), close()
- seek() → change file pointer
- tell() → current position
Example:
f = open("[Link]", "r")
data = [Link]()
[Link]()
------------------------------------------
13. EXCEPTION HANDLING
------------------------------------------
• try, except, else, finally
• Raise Exception:
raise ValueError("Invalid!")
• User-defined Exception:
class MyError(Exception):
pass
------------------------------------------
14. REGULAR EXPRESSIONS (re module)
------------------------------------------
• Common functions:
- search(), match(), findall(), split(), sub()
• Metacharacters:
. any character
^ start of string
$ end of string
* 0 or more
+ 1 or more
\d digit
\w alphanumeric
------------------------------------------
15. IMPORTANT PROGRAMS (Repeated in exams)
------------------------------------------
• Armstrong number check
• Perfect number check
• Check even-length words
• Reverse string removing “s”
• Power using lambda
• GCD using recursion
• Count vowels & consonants
• Dictionary square values
• File read/write programs
• Extract year, month, date, time using lambda
• Combine list of dictionary values
------------------------------------------
16. R PROGRAMMING BASICS (Extra Notes)
------------------------------------------
• R is used for statistical computing.
• Data Types:
- numeric, character, logical, vector, list, dataframe
• Operators:
- Arithmetic: + - * /
- Relational: < > == !=
• Control Structures:
- if, for, while
• Functions:
- mean(), sum(), length(), sqrt(), print()
• File Handling:
- [Link](), [Link]()
------------------------------------------
17. EXPECTED 8-MARK THEORY TOPICS
------------------------------------------
• Exception Handling
• Modules & Packages
• Datatypes in Python
• File Handling
• Loops with examples
• List/Dictionary methods
• Anonymous function
• Regular expressions
------------------------------------------
END OF NOTES
------------------------------------------