0% found this document useful (0 votes)
8 views

pythonansct

The document covers various Python programming concepts including namespaces, file object modes, data visualization with Matplotlib, multiple inheritance, classes, data hiding, method overloading and overriding, and exception handling. It also includes programming tasks such as reading and writing files, creating user-defined modules, and using command line arguments. Each section provides brief explanations and examples related to the respective topics.

Uploaded by

Prathmesh Patil
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)
8 views

pythonansct

The document covers various Python programming concepts including namespaces, file object modes, data visualization with Matplotlib, multiple inheritance, classes, data hiding, method overloading and overriding, and exception handling. It also includes programming tasks such as reading and writing files, creating user-defined modules, and using command line arguments. Each section provides brief explanations and examples related to the respective topics.

Uploaded by

Prathmesh Patil
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
You are on page 1/ 18

1. State use of namespace in python.

Ans:

A namespace in Python is a system that ensures unique names for variables, functions, and
objects by mapping them to their respective objects. Python has different types of
namespaces:

 Local Namespace (inside a function)


 Global Namespace (for module-level variables)
 Built-in Namespace (for built-in functions like print(), len())

2. Describe various modes of file object?Explain any two in detail.


Ans:
3. Write use of matplotlib package in python
Ans:

Matplotlib is a data visualization library used to create static, animated, and interactive plots.
It is mainly used for:

 Plotting graphs (line, bar, scatter plots)


 Customizing graphs with labels, legends, and colors
 Handling multiple subplots

Example:
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [10, 20, 25, 30]
plt.plot(x, y)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Simple Plot')
plt.show()

4. Write a python program to read contents of first.txt file and write same
content in second.txt file.
Ans:

OR
5. Explain multiple inheritance and write a python program to implement it
Ans:

6. Write a python program to create a user defined module that will ask your
program name and display the name of the program.
Ans:
7. Design a class Employee with data members :name,department and
salary.create methods for reading and printing employee information.
Ans:

8. Compare local and global variable .


Ans:
9. Write a python program to find area of circle using function.
Ans:

10.Write a Python program to create a class ‘Diploma’ having a method


‘getdiploma’ that prints “I got a diploma”. It has two subclasses namely
‘CO’ and ‘IF’ each having a method with the same name that prints “I am
with CO diploma” and ‘I am with IF diploma’ respectively. Call the method
by creating an object of each of the three classes.
Ans:
11.Define Data Hiding concept? Write two advantages of Data Hiding.
Ans:

12.Explain method overloading and overriding in python.


Ans:
ChatGPT answer:
13.Write a program to create class student with Roll no. and Name and
display its contents
Ans:

14.With neat example explain default constructor concept in Python


Ans:
In Python, a default constructor is a constructor that is automatically provided
by the Python interpreter if a class does not explicitly define its own __init__()
method.
o It does not accept any arguments (other than self).
o It does not perform any initialization (instance variables remain
unassigned unless defined elsewhere).

15.Describe 'Self Parameter with example


Ans:
In Python, the self parameter is a reference to the current instance of a class.
It is used to access class variables and methods within the class.

Key Points about self:


o Mandatory in Methods: The first parameter of any instance method
must be self. Python automatically passes the object instance when
calling the method.

o Not a Keyword: self is just a convention (you can use any name, but
self is recommended).

o Used to Access Instance Attributes: Inside methods, self.attribute refers


to instance-specific data.
16.Design a class student with data members : name, roll no., department,
mobile no. Create suitable methods for reading and printing student
information.
Ans:

Output:

17.With suitable example explain inheritance in Python


Ans:
Example:

18.Write syntax of defining class in Python.


Ans:

19.Explain method overloading and overriding in python.


Ans: Same As Above
20.What is command line argument? Write python code to add b) two
numbers given as input from command line arguments and print its sum.
Ans:
Command line arguments are inputs passed to a program when it is executed
from the terminal/command prompt.
Example:
python script.py arg1 arg2 arg3
python script.py arg1 arg2 arg3
21.Design a class student with data members : name, roll no., department,
mobile no. Create suitable methods for reading and printing student
information
Ans: Same As Above
22.Explain how try-catch block is used for exception handling in python
Explain how to use user defined function in python with example.
Ans:
23. Write a program for importing module for addition and subtraction of two
numbers.
Ans:
24.Write a program to open a file in write mode and append some content at
the end of file.
Ans:

25.Write a program to show user defined exception in Python.


Ans: Same As Q. no. 22
OR

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy