Python Methods vs Functions Quiz
FREE Online Courses: Dive into Knowledge for Free. Learn More!
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
What keyword is used to define both methods and functions?
CorrectIncorrect -
Question 2 of 10
2. Question
____ are independent of classes.
CorrectIncorrect -
Question 3 of 10
3. Question
____ can access or modify class attributes.
CorrectIncorrect -
Question 4 of 10
4. Question
Functions are created _____ a class and methods are created _____ a class.
CorrectIncorrect -
Question 5 of 10
5. Question
Which of the following statement(s) is/are true?
Statement 1: Functions inside a class are called methods.
Statement 2: All methods are functions but all functions are not methods.
CorrectIncorrect -
Question 6 of 10
6. Question
Choose a correct method call for the following code.
Code
>>> class Hello:
>>> def world(self):
>>> print(“Hello World”)
>>> obj = Hello()
CorrectIncorrect -
Question 7 of 10
7. Question
What is the output of the below code?
Code
>>> def add(num1, num2):
>>> return num1 + num2
>>> print(add(2, 3))
CorrectIncorrect -
Question 8 of 10
8. Question
What is the output of the below code?
Code
>>> class Subtract:
>>> def differnce(self, num1, num2):
>>> return num2 – num1
>>> sub = Subtract()
>>> print(sub.differnce(2,4))
CorrectIncorrect -
Question 9 of 10
9. Question
Read the code and choose the correct option.
Code
>>> class Dog:
>>> def bark(self):
>>> print(“Barking”)
>>> def create_dogs():
>>> dog1 = Dog()
>>> dog1.bark()
>>> create_dogs()
CorrectIncorrect -
Question 10 of 10
10. Question
What is the output of the below code?
Code
>>> class Employee:
>>> def __init__(self, id, pay):
>>> self.id = id
>>> self.pay = pay
>>> def increment(self):
>>> self.pay = self.pay*2
>>> return self.pay
>>> def total_increment(num):
>>> employees = []
>>> for id in range(1, num+1):
>>> employees.append(Employee(id, id*1000))
>>> increments = [emp.increment() for emp in employees]
>>> return sum(increments)
>>> print(total_increment(3))
CorrectIncorrect