Python Methods Quiz
FREE Online Courses: Transform Your Career – Enroll for Free!
Quiz Summary
0 of 10 Questions completed
Questions:
Information
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
Results
Results
0 of 10 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
Categories
- Not categorized 0%
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- Current
- Review / Skip
- Answered
- Correct
- Incorrect
-
Question 1 of 10
1. Question
Which keyword is used to define a method?
CorrectIncorrect -
Question 2 of 10
2. Question
What method(s) can be called using the class name?
CorrectIncorrect -
Question 3 of 10
3. Question
Which method contains the self parameter?
CorrectIncorrect -
Question 4 of 10
4. Question
Which of the following statement(s) is/are true?
Statement 1: Python does not support method overloading.
Statement 2: Operator overloading is possible in Python.
CorrectIncorrect -
Question 5 of 10
5. Question
In Python, ____ decorator is used to define a class method.
CorrectIncorrect -
Question 6 of 10
6. Question
What is the output of the below code?
Code
>>> class Fruit:
>>> def __init__(orange, name):
>>> orange.name = name
>>> mango = Fruit(“mango”)
>>> print(mango.name)
CorrectIncorrect -
Question 7 of 10
7. Question
What is the output of the below code?
Code
>>> class Loops:
>>> @staticmethod
>>> def print_strings(num, str):
>>> for i in range(num):
>>> print(str)
>>> Loops.print_strings(2, “Hello World”)
CorrectIncorrect -
Question 8 of 10
8. Question
What is the output of the below code?
Code
>>> class Basket:
>>> fruits = 0
>>> @classmethod
>>> def add_fruit(cls):
>>> cls.fruits += 1
>>> basket1 = Basket()
>>> basket1.add_fruit()
>>> basket1.add_fruit()
>>> basket2 = Basket()
>>> print(basket2.fruits)
CorrectIncorrect -
Question 9 of 10
9. Question
What is the output of the below code?
Code
>>> class Addition:
>>> def __init__(self, num):
>>> self.num = num
>>> def __add__(self, other):
>>> return self.num – other.num
>>> num1 = Addition(10)
>>> num2 = Addition(3)
>>> print(num1 + num2)
CorrectIncorrect -
Question 10 of 10
10. Question
What is the output of the below code?
Code
>>> class Cat:
>>> def __init__(self, age):
>>> self.age = age
>>> def set_age(self, num):
>>> self.age = num
>>> def get_age(self):
>>> return self.age
>>> cat1 = Cat(2)
>>> cat2 = Cat(4)
>>> cat1.set_age(cat2.get_age())
>>> cat2.set_age(5)
>>> cat3 = Cat(cat1.get_age() + cat2.get_age())
>>> print(cat3.get_age())
CorrectIncorrect