wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Programming Quiz

Total questions: 60

Worksheet time: 3600secs

Name
Class
Date
1.

Sanya is trying to output the string "May the odds favor you" in Python. How can she do it?

a)

print("May the odds favor you")

b)

echo("May the odds favor you")

c)

System.out("May the odds favor you")

d)

printf("May the odds favor you")

2.

Avni is trying to create a variable in Python with a value 22.6. How should she do it?

a)

int a = 22.6

b)

a = 22.6

c)

Integer a = 22.6

d)

None of the above

3.

Myra is learning Python and wants to know how to add a single-line comment in her code. What should she use?

a)

/* This is a comment */

b)

!! This is a comment

c)

// This is a comment

d)

# This is a comment

4.

Aanya is trying to represent 261500000 as a floating number in Python for her programming assignment. How should she do it?

a)

2.615E8

b)

261500000

c)

261.5E8

d)

2.6

5.

Kabir is learning about complex datatypes in Python. He wants to select the correct example of a complex datatype. Which one should he choose?

a)

3 + 2j

b)

-100j

c)

5j

d)

All of the above are correct

6.

Eshaan is trying to create a multi-line string in Python for his project. What is the correct way of doing it?

a)

str = ""My name is Kevin and I live in New York""

b)

str = """My name is Kevin and I live in New York"""

c)

str = "My name is Kevin and I live in New York"

d)

All of the above

7.

Advait is working on a project in Python and needs to convert the uppercase letters in a string to lowercase. How can he achieve this?

a)

lowercase()

b)

capitalize()

c)

lower()

d)

toLower()

8.

Ananya wants to extract the substring "Kevin" from the following string declaration in Python:

a)

str[11:16]

b)

str(11:16)

c)

str[11][16]

d)

str[11-16]

9.

Aashi is trying to access a specific character from her favorite string in Python. Which of the following is the correct way to access the character "K" from the string?

a)

str(11)

b)

str[11]

c)

str:9

d)

None of the above

10.

Mira is working on a project that requires her to parse dates from various text files. Which Python module should she use to parse dates in almost any string format?

a)

datetime module

b)

time module

c)

calendar module

d)

dateutil module

11.

Shreya is learning about different number systems in her programming class. Which of the following is the correct way to indicate Hexadecimal Notation in Python?

a)

str = '\62'

b)

str = '62'

c)

str = "62"

d)

str = '\x62'

12.

Neha is trying to extract a part of her favorite quote from the end of the string in Python. Which of the following methods should she use?

a)

Indexing

b)

Negative Indexing

c)

Begin with the 0th index

d)

Escape Characters

13.

Arnav wants to fetch characters from a given range in a string in Python. How can he do that?

a)

[:]

b)

in operator

c)

[]

d)

None of the above

14.

Aarav is learning Python and wants to know how to capitalize only the first letter of a sentence. What method should he use?

a)

uppercase() method

b)

capitalize() method

c)

upper() method

d)

None of the above

15.

Akhil is trying to find the maximum score from his test results stored in a tuple. What is the correct way to get the maximum value from the tuple in Python?

a)

print (max(myscores));

b)

print (maximum(myscores));

c)

print (myscores.max());

d)

print (myscores.maximum);

16.

Aarav wants to fetch and display only the keys of his stock portfolio Dictionary in Python. How can he do that?

a)

print(mystock.keys())

b)

print(mystock.key())

c)

print(keys(mystock))

d)

print(key(mystock))

17.

How can Krish align a string centrally in Python while working on his project?

a)

align() method

b)

center() method

c)

fill() method

d)

None of the above

18.

How can Ria access the value for the key "Product" in the following Python Dictionary:

a)

mystock["Product"]

b)

mystock("Product")

c)

mystock[Product]

d)

mystock(Product)

19.

Aashi is working on a Python project and needs to set the tab size to 6 in her strings. How can she achieve this?

a)

expandtabs(6)

b)

tabs(6)

c)

expand(6)

d)

None of the above

20.

Sanya is trying to organize her favorite fruits in Python. She wants to use a collection that uses square brackets for comma-separated values. Which collection should she use? Fill in the blanks with a Python collection.

a)

Lists

b)

Dictionary

c)

Tuples

d)

None of the above

21.

Sneha is trying to find the index of the first occurrence of the letter "i" in the string "This is my website". How can she do that?

a)

str.find("i")

b)

str.find(i)

c)

str.index()

d)

str.index("i")

22.

Viaan is trying to figure out how to display whether the date is AM/PM in Python. What should he use?

a)

Use the %H format code

b)

Use the %p format code

c)

Use the %y format code

d)

Use the %I format code

23.

In a programming class, Anika is trying to access a specific element from a Multi-Dimensional List. Which of the following is the correct way for her to do this?

a)

list[row_size:column_size]

b)

list[row_size][column_size]

c)

list[(row_size)(column_size)]

d)

None of the above

24.

Asher is working on a programming assignment in Python. He needs to understand which of the following Bitwise operators shifts the left operand value to the right, by the number of bits in the right operand? The rightmost bits while shifting fall off.

a)

Bitwise XOR Operator

b)

Bitwise Right Shift Operator

c)

Bitwise Left Shift Operator

d)

None of the Above

25.

Avni is trying to access specific elements in her tuple named "mytuple". How can she specify a range of index to print elements from it?

a)

print(mytuple[1:4])

b)

print(mytuple[1 to 4])

c)

print(mytuple[1-4])

d)

print(mytuple[].slice[1:4])

26.

Tisha is trying to learn how to correctly create a function in Python. Which of the following is the right way to define a function?

a)

demoFunction()

b)

def demoFunction()

c)

function demoFunction()

d)

void demoFunction()

27.

Myra is trying to declare a variable in Python for her project. Which one of the following is a valid identifier declaration in Python?

a)

str = "demo666"

b)

str = "666"

c)

str = "demo demo2"

d)

str = "$$$666"

28.

Arnav is working on a Python project and needs to ensure that all the characters in his input string are printable. How can he check this?

a)

print() method

b)

printable() method

c)

isprintable() method

d)

echo() method

29.

Aanya has a Dictionary of items she wants to manage. How can she delete an element with the key "Price" from her Dictionary?

a)

del dict['Price']

b)

del.dict['Price']

c)

del dict('Price')

d)

del.dict['Price']

30.

Divya is working on a Python project and needs to swap cases in her text, changing lowercase letters to uppercase and vice versa. How can she achieve this?

a)

casefold() method

b)

swapcase() method

c)

case() method

d)

title() method

31.

Aditi has a Dictionary in Python named "mystock" that contains various stock items. Which of the following is used to empty the Dictionary in Python?

a)

mystock.del()

b)

clear mystock

c)

del mystock

d)

mystock.clear()

32.

Anika wants to know how to display only the day number of years in Python. Can you help her?

a)

date.strftime("%j")

b)

date.strftime("%H")

c)

date.strftime("%I")

d)

date.strftime("%p")

33.

Akhil wants to display only the day number of years in Python. How can he achieve this?

a)

date.strftime("%j")

b)

date.strftime("%H")

c)

date.strftime("%I")

d)

date.strftime("%p")

34.

Aanya is trying to create a function in Python that can handle different numbers of students' scores. What is used in Python functions, if you have no idea about the number of arguments to be passed?

a)

Keyword Arguments

b)

Default Arguments

c)

Required Arguments

d)

Arbitrary Arguments

35.

Avni is trying to create a Dictionary in Python to store her favorite gadgets. What is the correct way for her to do this?

a)

mystock = {"Product": "Earphone", "Price": 800, "Quantity": 50}

b)

mystock = {"Product"- "Earphone", "Price"-800, "Quantity"-50}

c)

mystock = {Product[Earphone], Price[800], Quantity[50]}

d)

None of the above

36.

Aashi is organizing a study group for her Python class. She wants to know what feature allows her classmates to skip certain arguments or pass them in any order when they are calling a function in their code.

a)

Keyword arguments

b)

Default Arguments

c)

Required Arguments

d)

Arbitrary Arguments

37.

In a programming class, Avani is learning how to create a Dictionary of arguments in a Python function. What is to be used to achieve this?

a)

Arbitrary arguments in Python (*args)

b)

Arbitrary keyword arguments in Python (**args)

c)

Keyword Arguments

d)

Default Arguments

38.

Akhil is working on a Python project and needs to convert the lowercase letters in a string to uppercase. What method should he use?

a)

upper()

b)

uppercase()

c)

capitalize()

d)

toUpper()

39.

Kabir is trying to find the minimum score from his list of test results in Python. What is the correct way to get the minimum value from a List in Python?

a)

print (minimum(mylist));

b)

print (min(mylist));

c)

print (mylist.min());

d)

print (mylist.minimum());

40.

Sneha is trying to convert an integer to a float in her Python program. Which of the following correctly converts int to float in Python?

a)

res = float(10)

b)

res = convertToFloat(10)

c)

None of the above

41.

Aisha is trying to determine the type of a variable in her Python program. How can she do this?

a)

print(typeOf(a))

b)

print(typeof(a))

c)

print(type(a))

d)

None of the above

42.

Siya is trying to compare two values in her Python program to check if they are equal. Which operator should she use to perform this comparison?

a)

=

b)

in operator

c)

is operator

d)

== (Answer)

43.

Avani has a tuple of scores from her recent exams. What is the correct way to get the minimum score from her tuple?

a)

print (min(myscores));

b)

print (minimum(myscores));

c)

print (myscores.min());

d)

print (myscores.minimum);

44.

Myra wants to display only the current month's number in Python. How can she do that?

a)

date.strftime("%H")

b)

date.strftime("%I")

c)

date.strftime("%p")

d)

date.strftime("%m")

45.

Nikita and Vanya are working on a project where they need to determine if two variables point to the same object in memory. How can they compare the two objects to check whether they have the same memory locations?

a)

is operator

b)

in operator

c)

**

d)

Bitwise operators

46.

How to fetch and display only the values of a Dictionary in Python?

a)

print(mystock.value())

b)

print(mystock.values())

c)

print(values(mystock))

d)

print(value(mystock))

47.

Which operator is used in Python to raise numbers to the power?

a)

Bitwise Operators

b)

Exponentiation Operator (**)

c)

Identity Operator (is)

d)

Membership Operators (in)

48.

____________ represents key-value pair in Python?

a)

Tuples

b)

Lists

c)

Dictionary

d)

All the Above

49.

Which of the following Bitwise operators sets each bit to 1, if only one of them is 1, i.e. if only one of the two operands is 1?

a)

Bitwise XOR

b)

Bitwise OR

c)

Bitwise AND

d)

Bitwise NOT

50.

What is the correct way to get the maximum value from a List in Python?

a)

print (maximum(mylist));

b)

print (mylist.max());

c)

print (max(mylist));

d)

print (mylist.maximum());

51.

An example to correctly begin searching from the end range of index in Python Tuples. Let's say our Python Tuple has 4 elements

a)

print(mytuple[-3 to -1])

b)

print(mytuple[3-1])

c)

print(mytuple[].slice[-3:-1])

d)

print(mytuple[-3:-1])

52.

Which of the following Bitwise operators in Python shifts the left operand value to the left, by the number of bits in the right operand? The leftmost bits while shifting fall off.

a)

Bitwise XOR Operator

b)

Bitwise Right Shift Operator

c)

Bitwise Left Shift Operator

d)

None of the Above

53.

How to display only the current month's name in Python?

a)

date.strftime("%H")

b)

date.strftime("%B")

c)

date.strftime("%m")

d)

date.strftime("%d")

54.

___________ uses Parenthesis for comma-separated values in Python? Fill in the blanks with a Python collection?

a)

List

b)

Tuples

c)

None of the above

55.

How to create an empty Tuple in Python?

a)

mytuple = ()

b)

mytuple = (0)

c)

mytuple = 0

d)

mytuple =

56.

How to display only the day number of years in Python?

a)

date.strftime("%j")

b)

date.strftime("%H")

c)

date.strftime("%I")

d)

date.strftime("%p")

57.

Delete multiple elements in a range from a Python List

a)

del mylist[2:4]

b)

del mylist(2:4)

c)

del mylist[2 to 4]

d)

del mylist(2 to 4)

58.

How to fetch the last element from a Python List with negative indexing?

a)

print("Last element = ",mylist[0])

b)

print("Last element = ",mylist[])

c)

print("Last element = ",mylist[-1])

d)

None of the above

59.

What is the correct way to get the length of a List in Python?

a)

mylist.count()

b)

count(mylist)

c)

len(mylist)

d)

length(mylist)

60.

To get today's date, which Python module is to be imported?

a)

calendar module

b)

datetime module

c)

dateutil module

d)

None of the above