What will be the output of the following code?
def func(a, b=[]):
b.append(a)
return b
print(func(1))
print(func(2))
PYTHON TRAINING 2
Quiz
•
Computers
•
University
•
Hard
Devanjali Relan
Used 1+ times
FREE Resource
20 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What will be the output of the following code?
def func(a, b=[]):
b.append(a)
return b
print(func(1))
print(func(2))
[1], [2]
[1], [1, 2]
[1, 2], [1, 2]
[2], [1, 2]
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of the following code snippets correctly creates a generator?
def generator():
yield 1
yield 2
def generator():
return 1
return 2
def generator():
return [1, 2]
def generator():
return (1, 2)
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the output of the following code?
def multiply(a, b=1):
return a * b
print(multiply(5))
0
5
1
Error
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the result of the following code?
x = [1, 2, 3]
y = [4, 5, 6]
z = zip(x, y)
print(list(z))
[(1, 4), (2, 5), (3, 6)]
[(1, 2, 3), (4, 5, 6)]
[1, 4, 2, 5, 3, 6]
Error
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the output of the following code?
def foo(x, y):
return x + y, x - y
result = foo(5, 3)
print(result)
(8, 2)
8, 2
[8, 2]
(8, -2)
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What will be the output of the following code?
def foo():
try:
return 1
finally:
return 2
print(foo())
1
2
None
Error
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the output of the following code?
x = [1, 2, 3, 4]
y = [i * i for i in x if i % 2 == 0]
print(y)
[1, 4, 9, 16]
[4, 16]
[2, 4]
[1, 3]
20 questions
Python Programming Quiz
Quiz
•
9th Grade - University
15 questions
Scope of Variables in Python
Quiz
•
1st Grade - Professio...
20 questions
AI BootCamp: 2024 Edition- Session 1
Quiz
•
University
20 questions
PYTHON FUNCTION
Quiz
•
University
20 questions
Programming in Python
Quiz
•
University
15 questions
PROGRAMMING IN PYTHON - UNIT II - TEST 1 MCQS
Quiz
•
University
24 questions
Логикалык операторлор жана структуралар
Quiz
•
6th Grade - University
20 questions
Python Strings
Quiz
•
University
15 questions
Character Analysis
Quiz
•
4th Grade
17 questions
Chapter 12 - Doing the Right Thing
Quiz
•
9th - 12th Grade
10 questions
American Flag
Quiz
•
1st - 2nd Grade
20 questions
Reading Comprehension
Quiz
•
5th Grade
30 questions
Linear Inequalities
Quiz
•
9th - 12th Grade
20 questions
Types of Credit
Quiz
•
9th - 12th Grade
18 questions
Full S.T.E.A.M. Ahead Summer Academy Pre-Test 24-25
Quiz
•
5th Grade
14 questions
Misplaced and Dangling Modifiers
Quiz
•
6th - 8th Grade