[Go to site: main page, start]

0% found this document useful (0 votes)
23 views7 pages

Python Programming Question Bank

The document is a comprehensive question bank for Python programming, covering various topics such as the origin of Python, its features, data structures, file handling, and libraries like NumPy and Matplotlib. It includes theoretical questions, practical coding tasks, and comparisons between different programming concepts. The content is structured to facilitate learning and assessment for students studying Python.

Uploaded by

sunita1sharma002
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views7 pages

Python Programming Question Bank

The document is a comprehensive question bank for Python programming, covering various topics such as the origin of Python, its features, data structures, file handling, and libraries like NumPy and Matplotlib. It includes theoretical questions, practical coding tasks, and comparisons between different programming concepts. The content is structured to facilitate learning and assessment for students studying Python.

Uploaded by

sunita1sharma002
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Question Bank Python Programming

1. Explain the origin and need for Python programming.


2. List and explain five key features of Python.
3. Describe the basic structure of a Python program with an example.
4. Define identifiers in Python. What are the rules for naming identifiers?
5. What are reserved words in Python? Give any 10 examples.
6. What are escape sequences in Python? Demonstrate any three with
examples.
7. What is IDLE in Python? Explain its two modes.
8. Differentiate between relational, logical, and bitwise operators with
examples.
9. Explain variables and assignment statements with an example.
[Link] a Python program to demonstrate if-elif-else with nested conditions.
[Link] between mutable and immutable objects with examples
[Link] Python code to create, initialize, and slice a list.
[Link] list traversal using a loop
[Link] the following list operations with examples: concatenation,
repetition, membership.
[Link] a program using list methods: append(), extend(), and insert().
[Link] the usage of pop(), remove(), index(), and sort() methods on
a list.
[Link] is a set in Python? Give an example of creating and using a set.
[Link] is a tuple? Explain tuple operations with examples.
[Link] a program to create a dictionary, update its values, and delete a key.
[Link] the get(), update(), and copy() methods for dictionaries with
examples.
[Link] a function in Python. Explain the steps to define and call a function
[Link] between formal and actual arguments with examples.
[Link] keyword arguments and default arguments with a code example.
[Link] is recursion? Write a recursive function to calculate the factorial of a
number.
[Link] the scope and lifetime of variables in Python functions.
[Link] is a module in Python? How do you create and import a module?
[Link] between text files and binary files.
[Link] Python code to create, write, and append data to a text file.
[Link] a program to search and update data in a binary file.
[Link] CSV files in Python and demonstrate reading data from a CSV file.
[Link] class and object in Python with an example.
[Link] attributes and methods of a class with code.
[Link] are constructors in Python? Demonstrate their use with an example.
[Link] between public, protected, and private attributes.
[Link] inheritance and polymorphism in Python with examples.
[Link] is data hiding? How is it implemented in Python?
[Link] code to create a one-dimensional NumPy array and perform
reshaping.
[Link] element-wise and aggregate operations on a NumPy array.
[Link] Python code to draw a bar graph using Matplotlib.
[Link] Python code to create a pie chart using Matplotlib.
Previous year Questions:

1. Write short notes on the following:


(a) Elaborate – “Python is interpreted as well as integrated programming
language”?
(b) How unary operator is different from binary operator? Give example of
each.
(c) Explain the use of is and in method in Python programming?
(d) Differentiate between list and tuple with example.
(e) Explain the use of pandas library with an example?
(f) Justify the significance of self keyword? Give an example?
2.
(a) Explain while loop and for loop with an example. Elaborate difference
between them.
(b) Explain membership operator, identity operator, escape sequence,
slicing with an example?
3.
(a) Perform following slicing operation on string “PYTHON PROGRAMMING”:
string[2:15:2]; string[1:3]; string[6]; string[2]; string[3:14:3]
(b) Write a program to print string in right-angled triangle pattern?
4.
(a) Differentiate between mutable and immutable objects with examples?
(b) Explain tuple, list, sets, dictionary in Python? Each with example.
5.
(a) Explain list methods: append, extend, remove, index, pop, insert, sort?
Give example of each?
(b) Explain dictionary methods: len, str, clear, copy, update, get? Give
example of each.
6.
Explain the concept of class, objects, functions, data member with help of
program? Also explain call by value and call by reference?
7.
Explain the following terms with examples:
(i) Scope and lifetime of a function.
(ii) Importing modules.
(iii) Formal, Actual, Default, Keyword arguments.
(iv) Concept of modules.
8.
(a) Elaborate the importance of pip command to install any library in
Python?
(b) By using NumPy library in program, perform the following operations:
Creation of 1D array, Re-shaping of an Array, Array Slicing, Aggregate
Operations.
9.
(a) Explain file modes of file handling? Give example of each?
(b) Explain the use of NumPy, Pandas, Matplotlib in Python programming?
Give example of each?
10.
a) Give a brief account of the Origin and need for Python Programming.
b) What is IDLE? Write two modes of Python IDLE.
c) Explain any two methods of list with example.
d) Give a brief account of the Formal Arguments and Actual Arguments.
e) Differentiate between break and continue statements.
f) Explain any two features of Python Programming Language.
g) Differentiate between Mutable and Immutable Objects.
h) What is a membership operator in Python? Explain it with an
example.
i) Explain NumPy Library in brief.

11.
a) Explain in detail the various data types in Python Programming Language.
b) Differentiate between for Loop and while Loop with Python code.
12.
a) Explain in detail about the various Operators in Python Programming Language.
b) What is String in Python Programming Language? Give examples of various String
handling functions and methods in Python.
13.a) Explain the Dictionary and its various operations and methods with
examples.
b) Make a list of the first 10 letters of the alphabet, then use the slice to do
the following operations: (5)
[Link] the first 3 letters of the list
[Link] any 3 letters from the middle(6)
16.
a) Explain Tuples and its various operations and methods with examples.
b) Create a dictionary whose keys are month names and whose values are
the number of days in the corresponding months.
[Link] the user to enter a month name and use the dictionary to tell them
how many days are in that month.
[Link] all the keys in the alphabetical order.
[Link] out all the months with 31 days.

20.
a) Write a program that uses a user-defined function that accepts name
and gender (as M for Male, F for Female) and prefixes Mr. / Ms. based on
the gender. (5)
b) Explain any three methods of math module with an example. (5)

21.
a) Write a menu-driven program to implement a basic calculator. (5)
b) Explain any three methods of random module with an example. (5)

22.
(a) Create a binary file with roll number, name, marks and perform the
following operations:
Update the marks.
Delete the records.
Display the records.
b) Explain the features of the NumPy Library. Explain any two methods of
NumPy Library.

23.
a) Create a binary file with Item number, Name, Price and perform the
following operations:
Search the marks.
Append the records.
Display the records.
b) Explain the features of the matplotlib Library. Explain any two methods
of matplotlib Library.

Common questions

Powered by AI

Python's support for various programming paradigms provides great flexibility in solving different computational problems. Procedural programming is suited for straightforward, linear problems with functions and procedures. Object-oriented programming supports encapsulation and reusability through classes and objects, ideal for complex systems with interacting components. Functional programming in Python, via functions as first-class citizens with features like map and filter, allows for concise and testable code, beneficial in data processing tasks. This multiparadigm support enables Python to adapt to a wide spectrum of tasks ranging from simple scripts to complex distributed systems .

In Python, lists are mutable, meaning their elements can be changed, added, or removed after creation, which makes lists suitable for operations that require data modifications. Tuples, however, are immutable; once created, their elements cannot be altered. This immutability makes tuples useful for fixed data bundles and can enhance performance as they are easier to cache. In complex data operations, choosing between these structures depends on whether data mutability is needed and can impact performance and memory usage .

Creating a list in Python involves enclosing comma-separated elements within square brackets. For example, myList = [1, 2, 3]. Initialization can be done at creation or dynamically by appending elements. Slicing is performed using a colon operator to create sublists. For example, myList[1:3] returns elements from index 1 to 2. Slicing allows for easy extraction and manipulation of data subsets, facilitating decomposition of lists for analysis, manipulation, and improved algorithm performance by focusing only on relevant data sections .

Inheritance in Python allows a class, known as a child or subclass, to inherit attributes and methods from another class, called the parent or superclass. This promotes code reusability by eliminating redundancy. Polymorphism enables objects to be processed differently based on their data type or class, often allowing different classes to be treated uniformly through the same interface. Together, they enhance flexibility and scalability by allowing existing code to be extended with minimal modifications for new functionalities .

Text files in Python are structured as sequences of readable characters, often encoded in formats like UTF-8, making them suitable for textual data. Binary files store data in raw, byte-oriented binary formats and are used for non-text files like images or compiled code. Text files facilitate human readability and editing, while binary files are more compact and efficient for non-text data storage. The choice affects file I/O operations, as reading from or writing to binary files typically require handling data in byte sequences whereas text files work with strings .

Python is known for its simplicity and readability due to its clear syntax. It supports multiple programming paradigms, including procedural, object-oriented, and functional programming, allowing for flexible programming styles. Its extensive standard libraries facilitate a wide range of functionalities from database access to web services. Python's portability enables it to run on various platforms without modification. The dynamic typing and automatic memory management support ease of coding and reduce overhead. Additionally, Python's community and the availability of third-party modules make it a powerful tool for developers .

Escape sequences in Python are special sequences in strings that represent characters that are difficult to input directly into a text. They allow for proper string formatting and control of output, such as newline (\n), tab (\t), and backslash (\\). The newline escape sequence (\n) moves the cursor to a new line, facilitating multiline text output. The tab escape sequence (\t) inserts a horizontal tab, providing spacing in text. The backslash escape allows for including a backslash character in a string. These sequences help in creating text outputs that need specific formatting .

The self keyword in Python is used within class methods to refer to the instance of the object upon which the method is being called. It is automatically passed to all instance methods and is essential for accessing variables and methods of the class. By ensuring that each instance of the class operates on its own data, self maintains proper encapsulation and functionality. For example, in a class defining a car, self.speed can be used to modify or access the speed attribute specific to each car object .

Modules in Python encapsulate code into a namespace, promoting modularity and reusability. This allows developers to write reusable code blocks that can be imported into different programs, reducing redundancy. To create a module, place a set of functions and variables into a file with a .py extension. It is then imported into another script using the import statement. Modules can be user-defined or built-in, helping in organizing code and enhancing maintainability .

Constructors in Python, defined as __init__ methods, are special methods called automatically when an instance of a class is created. They initialize object attributes and set initial states unlike typical methods which are invoked after object creation. Constructors ensure each instance starts life with a valid state, minimizing errors related to uninitialized variables. For example, class Car: def __init__(self, model): self.model = model. When creating an object, car = Car('Toyota'), the model attribute is set upon object creation, essential for reliable program behavior .

You might also like