NEW
Font size
WorksheetsPython Programming Quiz for beginners
Total questions: 65
Worksheet time: 33mins
Which of the following is a valid Python identifier?
2value
value_2
value-2
value 2
Which keyword is used to define a function in Python?
func
define
def
function
What is the output of print(type(42))?
<class 'str'>
<class 'int'>
<class 'float'>
<class 'bool'>
Which operator is used for exponentiation in Python?
^
**
*
exp()
What is the result of 3 + 4 * 2 in Python?
14
11
10
7
Which of the following is a mutable data type?
tuple
str
list
int
What does indentation signify in Python?
Comments
Loop
Block of code
Variable
Which symbol is used to write a comment in Python?
//
#
/* */
--
What function is used to read input from the user?
input()
read()
scan()
get()
What is the output of print("Hello", end=" ")?
Hello end
Hello\n
Helloend
Hello
Which statement is used to skip the current iteration in a loop?
skip
continue
break
pass
What is the output of bool("False")?
False
True
Error
None
Which of the following is a correct way to convert a string to an integer?
int("123")
str(123)
float("123")
bool("123")
What does the is operator check?
Value equality
Type equality
Identity
Membership
Python is considered a:
Weakly typed language
Dynamically typed language
Statically typed language
Low-level language
How do you create a single element tuple
tuple(10)
(10)
(10,)
[10]
What is the default return value of a Python function that doesn't explicitly return anything?
0
None
False
undefined
Which of the following is a correct function definition?
def myfunc:
function myfunc()
def myfunc():
define myfunc()
What is the scope of a variable declared inside a function?
Global
Local
Static
Dynamic
Which statement is used to exit a function and return a value?
break
exit
return
stop
What is the output of "Python"[0]?
P
y
n
o
Which method is used to convert a string to lowercase?
lowercase()
toLower()
lower()
down()
What does the len() function return when applied to a string?
Number of words
Number of characters
Number of lines
Number of vowels
Which operator is used to concatenate strings in Python?
+
&
*
%
What is the output of "abc" * 3?
abcabcabc
abc3
abc abc abc
abc*3
Which method adds an item to the end of a list?
insert()
append()
add()
extend()
Which of the following creates a list?
{1, 2, 3}
(1, 2, 3)
[1, 2, 3]
<1, 2, 3>
What is the index of the first element in a Python list?
1
0
-1
None
Which method removes all items from a list?
delete()
clear()
remove()
pop()
Which method is used to get all keys from a dictionary?
keys()
values()
items()
get()
What is the output of len({"a":1, "b":2})?
1
2
3
0
Which method is used to remove a key from a dictionary?
delete()
remove()
pop()
discard()
What is the correct syntax to access the value of key "name" in a dictionary d?
d.name
d["name"]
d(name)
d->name
Which method returns all key-value pairs in a dictionary?
keys()
values()
items()
pairs()
Which of the following defines a tuple?
[1, 2, 3]
{1, 2, 3}
(1, 2, 3)
<1, 2, 3>
Tuples are:
Mutable
Immutable
Dynamic
Expandable
Which method is used to count occurrences of an element in a tuple?
count()
index()
find()
search()
Which of the following creates a set?
{1, 2, 3}
[1, 2, 3]
(1, 2, 3)
set(1,2,3)
Sets are:
Ordered
Mutable
Allow duplicates
Immutable
Which method adds an element to a set?
append()
add()
insert()
extend()
What is the difference between set and frozenset?
No difference
frozenset is mutable
set is immutable
frozenset is immutable
Which method removes all elements from a set?
clear()
remove()
discard()
pop()
Which of the following is used to define a block of code in Python?
Braces {}
Parentheses ()
Indentation
Semicolon ;
What is the output of len(set([1, 2, 2, 3]))?
2
3
4
1
Which function is used to get the index of an element in a tuple?
find()
search()
index()
position()
What is the output of print("Hello" + str(5))?
Hello5
Hello 5
Hello
Error
You are given a list numbers = [1, 2, 2, 3, 4]. You convert it into a set using unique = set(numbers) and then print len(unique). What will be the output?
5
4
3
2
Consider the tuple data = (10, 20, 30, 40). What will be the result of print(data[-1])?
10
20
30
40
text = "Python Programming"
reversed_text = text[::-1]
What will be printed when you run print(reversed_text)?
gnimmargorP nohtyP
PythonProgramming
ProgrammingPython
Error
You have two lists: a = [1, 2] and b = [3, 4]. You perform result = a + b and print it. What will be the output?
[1, 2, 3, 4]
[4, 3, 2, 1]
[1, 2][3, 4]
Error
A dictionary info = {"name": "Alice", "age": 25} is defined. You access the value of the key "age" using print(info["age"]). What will be printed?
Alice
name
25
Error
You define a string s = "abc" and multiply it by 3 using print(s * 3). What will be the output?
abcabcabc
abc3
abc abc abc
Error
A tuple t = (1, [2, 3], "hello") is created. You want to find out how many elements are in the tuple using len(t). What will be the result?
2
3
1
5
You have a string greeting = "hello" and apply the method greeting.upper() and print the result. What will be displayed?
HELLO
hello
Hello
error
A list items = [10, 20, 30] is defined. You use items.pop() to remove and return the last element. What will be printed?
10
20
30
Error
What will be the output of print({1, 2, 3} & {2, 3, 4})?
{1,4}
{2,3}
{1,2,3,4}
Error
What will be the output of print([i for i in range(5) if i % 2 == 0])
[1, 3, 5]
[0, 2, 4]
[2, 4]
[0, 2]
What will be the output of print({x: x**2 for x in range(3)})?
{0: 0, 1: 1, 2: 4}
{1: 1, 2: 4}
{0: 1, 1: 2, 2: 3}
Error
What is the output of print({1, 2, 3}.issubset({1, 2, 3, 4}))?
True
False
Error
None
fruits = ['apple', 'banana', 'cherry', 'date', 'elderberry']
print(fruits[:3])
['banana', 'cherry', 'date']
['apple', 'banana', 'cherry']
['cherry', 'date', 'elderberry']
['apple', 'cherry', 'elderberry']
What will be the output of the following code?
def f(x=[]):
x.append(1)
return x
print(f())
print(f())
[1] [1]
[1] [1, 1]
[1, 1] [1, 1, 1]
Error
Which of the following operations is not allowed on a tuple?
t[0]
t.index(5)
len(t)
t.append(3)
What is the output of this code?
s = set("hello")
s.add("h")
print(len(s))
5
6
4
Error
Consider the code:
lst = [1, 2, 3]
print(lst * 2)
lst *= 2
print(lst)
[1, 2, 3, 1, 2, 3] and [1, 2, 3, 1, 2, 3]
[1, 2, 3, 1, 2, 3] and [1, 2, 3]
[1, 2, 3] and [1, 2, 3, 1, 2, 3]
Error
What does this function return?
def mystery(a, b):
return a if a > b else b if b > a else a + b
print(mystery(3, 3))
3
6
9
Error
