Python Question Bank
Python Question Bank
(AUTONOMOUS)
Question Bank
Defined within the class block but outside Defined within methods, typically
of methods the __init__ constructor
Shared among all instances of the class Specific to each instance of the class
Changing affects all instances of the class Changing affects only the specific instance
2. What is polymorphism?
The polymorphism means having many forms. In programming, polymorphism means the
same function name (but different signatures) being used for different types. The key difference is
the data types and number of arguments used in function .
3. Write the uses of _init_method.
__init__ method in Python is used to initialize objects of a class. It is also called a constructor.
constructors are used to initialize the object’s state.
The task of constructors is to initialize(assign values) to the data members of the class when an
object of the class is created.
4. Define Aggregation.
Aggregation is a concept in which an object of one class can own or access another independent
object of another class.
It represents Has-A’s relationship.
It is a unidirectional association i.e. a one-way relationship. For example, a department can
have students but vice versa is not possible and thus unidirectional in nature.
In Aggregation, both the entries can survive individually which means ending one entity
will not affect the other entity.
5. How to open a new file in Python?
Opening a file creates a file object. In this example, the variable f refers to the new file object. >>> f
= open("test.dat","w") >>> print f The open function takes two arguments. The first is the name of
the file, and the second is the mode. Mode "w" means that we are opening the file for writing.
6. Which method is used to read the contents of a file which is already created?
The read method reads data from the file. With no arguments, it reads the entire contents of the file:
>>> text = f.read()
A text file is a file that contains printable characters and whitespace, organized into lines separated by
newline characters. To demonstrate, we‘ll create a text file with three lines of text separated by newlines:
>>> f = open("test.dat","w")
>>> f.close()
Whenever a runtime error occurs, it creates an exception. Usually, the program stops and Python
prints an error message.
Pickling is so called because it ―preserves‖ data structures. The pickle module contains the
necessary commands. To use it, import pickle and then open the file in the usual way: >>> import
pickle >>> f = open("test.pck","w")
break
except ValueError:
11. List some few common Exception types and explain when they occur.
ArithmeticError- Base class for all errors that occur for numeric calculations.
• OverflowError- Raised when a calculation exceeds maximum limit for a numeric type.
• ZeroDivisionError- Raised when division or modulo by zero takes o place.
• ImportError- Raised when an import statement fails.
• IndexError- Raised when an index is not found in a sequence.
• RuntimeError- Raised when a generated error does not fall into any category.
Syntax
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
);
14. Define SQLite Manager.
SQLite is a relational database management system contained in a C programming library. In
contrast to many other database management systems, SQLite is not a client–server database engine.
Rather, it is embedded into the end program. SQLite is an open source SQL database that stores data
to a text file on a device.
15. List the various data manipulation commands in SQL.
SQL commands are essential for managing databases effectively. These commands are divided
into categories such as Data Definition Language (DDL), Data Manipulation Language (DML),
Data Control Language (DCL), Data Query Language (DQL), and Transaction Control Language
(TCL).
16. What do you mean by GUI programming?
A Python GUI, or Graphical User Interface, is a visual interface that allows users to interact
with a software application. It provides users with a set of graphical elements, such as
buttons, checkboxes, dropdown lists, and sliders, to perform various tasks and access
different functionalities of the application.
Layered approach. The layered approach used in designing Tkinter gives Tkinter all of the
advantages of the TK library. ...
Accessibility. Learning Tkinter is very intuitive, and therefore quick and painless. ...
Portability. ...
Availability.
19. Enlist the advantages of using SQL in python.
Faster Query Processing
No Coding Skills
Standardized Language
Portable
Interactive Language
20. How do you write a SELECT statement to retrieve data from a table?
3. Describe about Python Files, its types, functions and operations that can be performed on files
with examples.