NEW
Font size
WorksheetsPython Programming Quiz 1
Total questions: 30
Worksheet time: 15mins
What is the output of print(10 // 3)?
3.33
3
4
Error
Which of the following is a valid Python function definition?
def func:
def func()
function func()
func def()
What does type([]) return?
list
[]
type
Which operator is used for exponentiation in Python?
^
**
exp()
^^
What is the output of bool([])?
True
False
None
Error
What does 'hello'.capitalize() return?
'Hello'
'hello'
'HELLO'
'Hello '
Which method checks if a string ends with a specific substring?
ends()
finish()
endswith()
close()
What is the result of 'abc'.find('b')?
0
1
2
-1
What is the output of [1, 2, 3] + [4]?
[1, 2, 3, 4]
[5, 6, 7]
[1, 2, 3][4]
Error
Which method removes a specific item from a list?
delete()
remove()
pop()
discard()
What is the output of list(range(3))?
[0, 1, 2]
[1, 2, 3]
[0, 1, 2, 3]
range(3)
What does my_list[::-1] do?
Reverses the list
Sorts the list
Removes duplicates
Returns first item
Which method adds multiple items to a list?
append()
extend()
insert()
add()
What is the output of {'a': 1, 'b': 2}['b']?
1
2
'b'
Error
Which method returns all key-value pairs in a dictionary?
items()
values()
keys()
pairs()
What does dict.get('x', 0) return if 'x' is not a key?
None
'x'
0
Error
Which method merges two dictionaries?
combine()
update()
append()
merge()
What is the output of len({'a': 1, 'b': 2})?
1
2
3
0
What is the output of lambda x: x + 2 when called with 3?
5
6
3
Error
Which keyword is used to return a value from a function?
yield
return
output
send
What is a default parameter in a function?
Always required
Must be last
Has no value
Can be skipped
Which of these is a valid function call?
func[]
func{}
func()
func<>
What is the output of tuple([1, 2])?
(1, 2)
[1, 2]
{1, 2}
1, 2
Which of these is an immutable data type?
List
Dictionary
Tuple
Set
How do you access the second item in a tuple t = (10, 20, 30)?
t[2]
t[1]
t(1)
t{1}
What is the output of len((1, 2, 3))?
2
3
1
0
Which method is used to count occurrences in a tuple?
count()
index()
find()
search()
What is the output of set([1, 2, 2, 3])?
{1, 2, 3}
[1, 2, 3]
(1, 2, 3)
{1, 2, 2, 3}
Which operation checks membership in a set?
in
has()
contains()
exists()
What is the result of {1, 2} & {2, 3}?
{1, 3}
{2}
{1, 2, 3}
{}
