




































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





































50+ practical programs Syntax + concepts MCQs + viva questions Exam + practical preparation Quick revision sheets Original student-friendly explanations
Prepared as an original learning resource. Verify syntax against your Python version and course requirements.
TABLE OF CONTENTS
1. Python & Programming Basics 2. Installing Python & Running Code 3. Variables & Data Types 4. Operators & Expressions 5. Input, Output & Type Conversion 6. Conditional Statements 7. Loops 8. Strings 9. Lists 10. Tuples, Sets & Dictionaries 11. Functions 12. Modules & Packages 13. File Handling 14. Exception Handling 15. Object-Oriented Programming 16. Useful Built-in Functions 17. Problem-Solving Patterns 18. 50+ Practice Programs 19. MCQs & Viva 20. Final Revision Sheet
How to use these notes: Read the concept → type the example yourself → change the input → solve the practice task without looking.
1. Python & Programming Basics — Practice &
Revision
Example
a = 12 b = 19 if b > a: print("b is larger") else: print("a is larger")
Key points
Indentation is meaningful in Python. Comments begin with #. Python is case-sensitive: age, Age and AGE are different names.
Quick review: Explain the main idea in your own words and write one small program without copying.
2. Installing Python & Running Code
The official Python distribution includes the interpreter and standard library. On a computer, Python programs are commonly saved with the .py extension.
You can run code interactively in the Python shell or save a script and run it from an IDE/editor or terminal.
Use a virtual environment for projects when you need isolated packages. Keep project files organized and use meaningful filenames.
Basic workflow
Create a file such as main.py → write code → save → run → read the error/output → test with multiple inputs → improve.
Version check
python --version
3. Variables & Data Types
A variable name refers to a value. Python determines the type at runtime, so explicit type declarations are normally unnecessary.
Common built-in types include int, float, complex, bool, str, list, tuple, set and dict. None represents the absence of a value.
Examples
age = 16 price = 49.5 name = "Kirti" passed = True nothing = None
Checking types
x = 25 print(type(x)) print(isinstance(x, int))
3. Variables & Data Types — Practice & Revision
Naming rules
A name may contain letters, digits and underscores but cannot start with a digit. Avoid keywords such as if, for, class and return. Prefer snake_case for variables.
Practice
Create variables for your name, age, school, percentage and whether you like coding. Print each value and its type.
Quick review: Explain the main idea in your own words and write one small program without copying.
4. Operators & Expressions — Practice & Revision
Parentheses are evaluated first, followed by exponentiation, multiplication/division/floor division/modulo, then addition/subtraction. Use parentheses when clarity matters.
Practice
Write expressions for: area of a circle, average of three numbers, remainder after division, and checking whether a number is between 10 and 50.
Quick review: Explain the main idea in your own words and write one small program without copying.
5. Input, Output & Type Conversion
input() reads text from the user. Convert it when numeric operations are required. print() displays values and supports separators and end characters.
Example
name = input("Name: ") age = int(input("Age: ")) print(f"Hello {name}, next year you will be {age + 1}.")
Conversions
int("25") → 25; float("3.5") → 3.5; str(100) → "100"; bool(0) → False.
6. Conditional Statements
Use if when code should run only when a condition is true. elif checks another condition. else handles the remaining case.
Example
marks = float(input("Marks: ")) if marks >= 90: grade = "A" elif marks >= 75: grade = "B" elif marks >= 60: grade = "C" else: grade = "D" print(grade)
Nested conditions
A condition can contain another condition, but excessive nesting can reduce readability. Combine simple conditions with and/or where appropriate.
6. Conditional Statements — Practice & Revision
Common mistakes
Using = instead of == in a comparison; forgetting indentation; creating overlapping or unreachable conditions.
Practice
Build a simple menu program that asks for a number and reports whether it is positive, negative or zero.
Quick review: Explain the main idea in your own words and write one small program without copying.
7. Loops — Practice & Revision
Control statements
break exits a loop. continue skips to the next iteration. Use them carefully so loop logic stays easy to follow.
Practice
Print the multiplication table of a number; find the sum of 1 to n; count vowels in a word; print all even numbers from 1 to 100.
Quick review: Explain the main idea in your own words and write one small program without copying.
8. Strings
A string is an immutable sequence of characters. Strings can be indexed and sliced. Indexing starts at 0; negative indexes count from the end.
Examples
text = "Python" print(text[0]) print(text[-1]) print(text[1:4]) print(text[::-1])
Useful methods
lower(), upper(), strip(), split(), join(), replace(), find(), startswith(), endswith(), count().
9. Lists
A list is an ordered, mutable collection. It can contain values of different types, although keeping related types together is usually clearer.
Examples
nums = [10, 20, 30] nums.append(40) nums.insert(1, 15) nums.remove(20) print(nums)
Slicing
nums[1:4], nums[:3], nums[::2]. List slicing creates a new list.
Useful methods
9. Lists — Practice & Revision
append, extend, insert, remove, pop, clear, index, count, sort, reverse, copy.
List comprehension
squares = [x*x for x in range(1, 6)]
Practice
Find largest/smallest number, remove duplicates, calculate sum and average, separate even and odd numbers.
Quick review: Explain the main idea in your own words and write one small program without copying.