Chapter 1: Python Revision Tour - I
Key Concepts:
- Tokens: Keywords, Identifiers, Literals, Operators, Punctuators
- Variables and Assignment
- Data Types: int, float, str, bool, list, tuple, dict
- Type Casting
- Operators: Arithmetic, Relational, Logical, Assignment
- Input/Output: input(), print()
- Flow of Control: if, if-else, if-elif, loops (for, while), break, continue
Subjective Questions:
- What are the different types of tokens in Python?
- Explain the difference between = and == in Python.
- What is type casting? Give examples.
- Differentiate between list and tuple.
- What is the role of break and continue?
- Write a program to check if a number is even or odd.
- Write a program to print the sum of first 10 natural numbers.
- How is input taken in Python?
- What is the purpose of elif in conditional statements?
- Explain mutable and immutable datatypes with examples.
MCQs:
1. Output of print(type(3.0))?
a) <class 'int'> b) <class 'float'> (Correct) c) <class 'double'> d) Error
2. Invalid identifier?
a) _value b) 2value (Correct) c) value_2 d) val_ue
3. Output of print(bool(0))?
a) True b) False (Correct) c) 0 d) Error
4. Entry controlled loop?
a) for (Correct) b) while (Correct) c) both (Correct) d) None
5. Output of print(5 // 2)?
a) 2.5 b) 2 (Correct) c) 3 d) 2.0
Chapter 2: Python Revision Tour - II
Key Concepts:
- List: Mutable, ordered; Methods: append(), insert(), remove(), pop(), sort(), etc.
- Tuple: Immutable, ordered; Methods: index(), count()
- Dictionary: Key-value pairs; Methods: keys(), values(), items(), get(), update(), etc.
- String Operations: Slicing, indexing; Methods: find(), replace(), upper(), lower(), etc.
- Membership & Identity Operators: in, not in, is, is not
Subjective Questions:
- Explain any 4 methods of list with syntax and example.
- Differentiate between list and tuple.
- How is a dictionary different from a list?
- Write a program to input 5 names in a list and sort them alphabetically.
- What is slicing in strings? Give example.
- Write a program to count vowels in a string.
- What are the advantages of using dictionary?
- Write a program to display all keys and values of a dictionary.
- What happens when we try to modify a tuple?
- Write a program to input a string and print all words that are in uppercase.
MCQs:
1. Output of len({'a':1, 'b':2})?
a) 1 b) 2 (Correct) c) Error d) 3
2. Method to add an element to list?
a) add() b) insert() c) append() (Correct) d) extend()
3. Output of 'hello'.isalpha()?
a) True (Correct) b) False c) Error d) None
4. Which is immutable?
a) List b) String (Correct) c) Dictionary d) None
5. Output of t=(1,2,3); t[1]=5?
a) (1,5,3) b) Error (Correct) c) None d) [1,5,3]
Chapter 3: Working with Functions
Key Concepts:
- Function Basics: def, return vs print
- Types of Functions: Built-in, User-defined
- Function Parameters: Positional, Default, Keyword, *args, **kwargs
- Scope of Variables: Local, Global, global keyword
- Recursion: Function calling itself, base condition required
Subjective Questions:
- Define a function. What are the advantages of using functions?
- Explain the difference between return and print in a function.
- What are default arguments? Give an example.
- Write a function that returns factorial using recursion.
- Differentiate between local and global variables with code.
- Write a function to return sum of even numbers from a list.
- What is *args and **kwargs? Explain with examples.
- Write a function to check if a string is a palindrome.
- Explain the use of keyword arguments with an example.
- What happens if a function does not have a return statement?
MCQs:
1. Output of add(3) with def add(a, b=2)?
a) 5 (Correct) b) 3 c) 2 d) Error
2. Scope of variable inside a function?
a) Global b) Local (Correct) c) Universal d) External
3. Keyword to return value?
a) break b) return (Correct) c) yield d) output
4. Output of test(1,2,3) with def test(*args): return len(args)?
a) 0 b) 3 (Correct) c) 1 d) Error
5. Recursive function?
a) Calls another function b) Calls itself (Correct) c) Has parameters d) Returns value
Chapter 5: File Handling
Key Concepts:
- Types of Files: Text, Binary, CSV
- File Operations: open(filename, mode), Modes: r, w, a, rb, wb
- Text File: read(), readline(), readlines(), write(), writelines(), with open()
- Binary File: Uses pickle module, dump(), load()
- CSV File: Uses csv module, reader, writer
Subjective Questions:
- Differentiate between text file and binary file.
- Write a program to count number of lines in a text file.
- Write a program to write and read list of strings to a text file.
- What is the purpose of with open()? How is it better?
- Write a program to read file line by line.
- How is binary file read and written using pickle?
- Write a program to store and read dictionary in binary file.
- Difference between 'w' and 'a' mode?
- Write a program to read and display CSV file content.
- What is seek()? How does it work?
MCQs:
1. Module used for binary file?
a) os b) file c) pickle (Correct) d) binary
2. Output of [Link]() on empty file?
a) None b) 0 c) '' (Correct) d) Error
3. Function of writelines()?
a) Write one by one b) Write list of strings (Correct) c) Write numbers d) None
4. Mode for appending?
a) 'r' b) 'w' c) 'a' (Correct) d) 'x'
5. Syntax for writing CSV?
a) [Link](file) (Correct) b) [Link](file) c) [Link](file) d) [Link]()