pythan-PTT II Question Bank With Answer 1
pythan-PTT II Question Bank With Answer 1
b. hasattr() : Returns True if the specified object has the specified attribute
(property/method).
Syntax:
Example:
C = lamhda b:b**3
class car():
def show(self):
print("Model is", self.model )
print("color is", self.color )
• The definition of the method is different in parent and child classes but the
name stays the same.
6) Explain Concept of Module In detail.
Syntax:
Import module_name
Example:
Import math as mp
Mp.floor(1.5)
2
In order to open a file, python has provided a built in function called as open()
function.
This function return the file object. While opening a file we can specify the
mode in which we wan open file.
Syntax:
f = open(“file_name”)
8) Explain any two standard library.
python also supports concept of local and global variable. By default every
variable declared has global scope. If a variable is defined within a function,
then the scope is local.
Local Variable :
Local variables are those which are initialized inside a function and belongs only
to that particular function. It cannot be accessed anywhere outside the function.
Ex.,
def f():
# local variable
s = "I love Geeksforgeeks"
print("Inside Function:", s)
# Driver code
f()
print(s)
Global Variable :
The global variables are those which are defined outside any function and which
are accessible throughout the program i.e. inside and outside of every function
Ex.,
# This function uses global variable s
def f():
print("Inside Function", s)
# Global scope
s = "I love Geeksforgeeks"
f()
print("Outside Function", s)
11) Explain need & Types of Function.
• To improve the readability of the source code.
• To provides the facility of the reusability of the code, same function can be
used in any program rather than writing the same code from scratch.
• Function provides modular programming hence debugging of the code
would be easier, as errors are easy to be traced.
• Reduces the size of the code, duplicate set of statements are replaced by
function calls.
Types of Function :
1) User Defined Function :
These types of functions are defined by the user as per their requirement.
2) Built-In Function :
These functions are provided by the python. As the name suggests these are
built-in you can Directly use it.
e.g. print0 function in python