This document discusses various file handling concepts and operations in Python including:
1. Methods like join() and split() for manipulating file paths as well as the difference between absolute and relative file paths.
2. Using the shelve module to save variables and compressing files with examples of reading ZIP files.
3. Common file operations like copying, moving and deleting files and folders with an example.
4. Using assertions and exceptions in a function to validate parameters and handle errors.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
34 views
Python Question Bank - 2nd IA
This document discusses various file handling concepts and operations in Python including:
1. Methods like join() and split() for manipulating file paths as well as the difference between absolute and relative file paths.
2. Using the shelve module to save variables and compressing files with examples of reading ZIP files.
3. Common file operations like copying, moving and deleting files and folders with an example.
4. Using assertions and exceptions in a function to validate parameters and handle errors.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
1.
Illustrate join() and split() methods with examples
2.With the concept of file path, discuss absolute and relative file path. 3. Analyze saving variables with the shelve module. 4. Illustrate the benefits of compressing files. Also, explain the reading of a ZIP File with an example. 5. Bring about the use of the following file operation in Python with a suitable example. i) Copying files and folders ii) Moving files and folders iii)Permanently deleting files and folders 6. Develop the role of assertions in Python with suitable program. 7. Write a function named DivExp which takes two parameters a,b and returns a value c (c=a/b).Write suitable assertion for a>0 in function DivExp and raise an exception for when b=0.Develop a suitable program,which reads two values from the console and calls a function DivExp. 8. Explain the terms with example:(i)Class,(ii)objects & (iii)instance variables 9. Explain how we can change the state of an object by making an assignment to one of its attributes 10. Define class and object, Construct the class called rectangle and initialize it with height=100,width=200, starting point as (x=0.y=0).Write a program to display the center point coordinates of a rectangle. 11. Briefly explain the printing of objects with an example. 12. Explain the concept of copying using copy module with an example. 13. Explain negative indexing, slicing, remove() and pop(). 14. Explain the use of in and not in operators in list with suitable examples. 15. Explain the concept of file path. Also discuss about absolute and relative file paths. 16. List out the differences between shutil.copy() and shutil.copytree() methods. 17. Explain different methods or modes for opening the file with example 18. Develop a Python program to traverse the current directory by listing sub- folders and files. 19. Explain the methods __init__ and __str__ with suitable code example to each. 20. Read a multi-digit number (as chars) from the console. Develop a program to print the frequency of each digit with suitable message Explain the following with syntax and suitable code snippet: i) Class definition ii) instantiation iii) passing an instance (or objects) as an argument iv) instances as return values. 21. Define a function which takes 2 objects representing complex numbers and returns a new complex number with the addition of 2 complex numbers. Define a suitable class ‘complex’ to represent the complex number. Develop a program to read N (N≥2) complex numbers and to compute the addition of N complex numbers. 22. Create a Time class with hour, min and sec as attributes. Demonstrate how two Time objects would be added. 23. Develop a program to backing Up a given Folder (Folder in a current working directory) into a ZIP File by using relevant modules and methods. 24. Briefly, explain the printing of objects with suitable examples.