Python Scripting - Week 7 Flashcards

1
Q

What is the abbreviations of OOP ?

A

Object Oriented Programming

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is not a object in python ?

A

Reserved keywords are not objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Can we assighn objects to variables ?

A

Yes,
print is an function object , we can assign it to variable and use it as print function ?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is class instance ?

A

x = MyClass()
object of class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to Define a class in Python ?

A

class myclass:
x=1234
def f():
return ‘Hello World’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to access class variable ?

A

class myclass:
x=1234
def f():
return ‘Hello World’
a=myclass()
print(f”Class Variable : {a.x}”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to access class method ?

A

class myclass:
x=1234
def f():
return ‘Hello World’
a=myclass()
print(f”Class Variable : {a.x}”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the first argument of function in class ?

A

The first argument of a function in class is always self , self is an instance of class, it implicitly passed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which class object is mutable by class instance ?

A

I you want to modify class variable by class instance , you have to use list.
class Car():
num=[]
def __init__(self):
pass
a=Car()
a.num.append(1)
Car.num.append(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which function returns list of the attributes and methods of any object ?

A

dir() is a powerful inbuilt function in Python3, which returns list of the attributes and methods of any object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Define a dunder method ?

A

class Book:
def __str__(self):
return f”Its a Book Method”

b=Book()
print(b)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to print class instance ?

A

We have to use dunder method
def__str__(self):
return f”This string will be printed when class instance is printed “

How well did you know this?
1
Not at all
2
3
4
5
Perfectly