wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

py_2

Total questions: 42

Worksheet time: 21mins

Name
Class
Date
1.

How can comments be used in Python programming?

a)

To execute code

b)

To document code

c)

To increase execution speed

d)

To create variables

2.

Which of the following best explains the use of str, int, and float values and variables in Python?

a)

They are used to store and manipulate text, whole numbers, and decimal numbers respectively.

b)

They are used to define functions and classes in Python.

c)

They are used to handle file operations in Python.

d)

They are used to manage memory allocation in Python.

3.

What are arithmetic expressions in Python?

a)

A combination of numbers and operators that computes a value

b)

A type of loop in Python

c)

A function definition in Python

d)

A syntax error in Python

4.

How is string concatenation performed in Python?

a)

Using the '+' operator

b)

Using the '-' operator

c)

Using the '*' operator

d)

Using the '/' operator

5.

What are special characters in strings, and how are they used in Python?

a)

Special characters are used to format strings.

b)

Special characters are used to represent whitespace.

c)

Special characters are used to escape characters in strings.

d)

Special characters are used to concatenate strings.

6.

Which of the following describes the use of the built-in functions print(), input(), str(), float(), int(), and round() in Python?

a)

They are used for file handling operations.

b)

They are used for mathematical computations only.

c)

They are used for basic input/output and type conversion operations.

d)

They are used for network programming.

7.

Function chaining in Python is used to:

a)

Execute multiple functions in a single line

b)

Create a chain of linked lists

c)

Connect multiple Python scripts

d)

Chain decorators together

8.

What is the purpose of indentation in Python coding?

a)

To improve code readability

b)

To define code blocks

c)

To make the code run faster

d)

To add comments to the code

9.

Which of the following describes the use of Python comments, including 'commenting out' portions of Python code?

a)

Python comments are used to explain code and can be used to temporarily disable code by 'commenting out'.

b)

Python comments are used to execute code faster.

c)

Python comments are used to compile code.

d)

Python comments are used to encrypt code.

10.

Which of the following describes the data types: str, int, float?

a)

str is a string, int is an integer, float is a floating-point number.

b)

str is a number, int is a string, float is a character.

c)

str is a floating-point number, int is a string, float is an integer.

d)

str is a character, int is a floating-point number, float is a string.

11.

Which of the following are recommendations for creating a Python variable name?

a)

Use meaningful names

b)

Start with a number

c)

Include special characters

d)

Use underscores to separate words

12.

Distinguish between underscore notation and camel case.

a)

Underscore notation uses underscores to separate words, while camel case capitalizes the first letter of each word except the first.

b)

Camel case uses underscores to separate words, while underscore notation capitalizes the first letter of each word except the first.

c)

Both underscore notation and camel case use underscores to separate words.

d)

Both underscore notation and camel case capitalize the first letter of each word except the first.

13.

Which of the following describes the evaluation of an arithmetic expression, including order of precedence and the use of parentheses?

a)

Evaluation is done from left to right, ignoring parentheses.

b)

Operators with higher precedence are evaluated first, and parentheses can alter the precedence.

c)

All operations are evaluated simultaneously.

d)

Parentheses are ignored in arithmetic expressions.

14.

Distinguish among these arithmetic operators: /, //, and %.

a)

The / operator performs integer division, // performs floating-point division, and % gives the remainder.

b)

The / operator performs floating-point division, // performs integer division, and % gives the remainder.

c)

The / operator gives the remainder, // performs integer division, and % performs floating-point division.

d)

The / operator performs integer division, // gives the remainder, and % performs floating-point division.

15.

What is the use of the += operator in a compound arithmetic expression?

a)

It adds the right operand to the left operand and assigns the result to the left operand.

b)

It subtracts the right operand from the left operand and assigns the result to the left operand.

c)

It multiplies the right operand with the left operand and assigns the result to the left operand.

d)

It divides the left operand by the right operand and assigns the result to the left operand.

16.

Which of the following functions is used to convert a string to an integer in Python?

a)

int()

b)

float()

c)

print()

d)

str()

e)

input()

17.

What is the consequence of incorrect indentation in Python?

a)

It causes an error

b)

It improves performance

c)

It has no effect

d)

It makes the code run faster

18.

What is the purpose of the 'counter' variable in the given Python program?

a)

To keep track of the number of iterations

b)

To store the final result of the program

c)

To act as a flag for conditional statements

d)

To hold temporary data during execution

19.

In the given Python program, what is the condition for the while loop to continue executing?

a)

The loop continues while a variable is less than 10.

b)

The loop continues while a variable is not equal to 0.

c)

The loop continues while a variable is greater than 5.

d)

The loop continues while a variable is equal to 1.

20.

What is one reason to use comments in code?

a)

To make the code run faster

b)

To explain the purpose of the code

c)

To increase the file size

d)

To confuse other developers

21.

True or False: You should use comments to describe portions of code that are hard to understand, but don’t overdo them.

a)

True

b)

False

22.

What is an example of a string data type in Python?

a)

A) 21

b)

B) 'Mike'

c)

C) 21.9

d)

D) -25.2

23.

Fill in the blank: An example of an integer data type in Python is ____.

a)

450

b)

45.0

c)

'450'

d)

True

24.

Which of the following is a floating-point data type example in Python?

a)

'Please enter name: '

b)

0

c)

3.1416

d)

-25

25.

Which of the following is a correct rule for naming a variable in Python?

a)

A) A variable name must begin with a number.

b)

B) A variable name can contain spaces.

c)

C) A variable name must begin with a letter or underscore.

d)

D) A variable name can be the same as a keyword.

26.

True or False: A variable name can begin with a number, but can use numbers later in the name.

a)

True

b)

False

27.

What is the use of the 'break' keyword in Python?

a)

To exit a loop prematurely

b)

To pause the execution of a program

c)

To define a function

d)

To handle exceptions

28.

What is the use of the 'continue' keyword in Python?

a)

To exit a loop immediately

b)

To skip the current iteration and continue with the next

c)

To pause the execution of a loop

d)

To terminate the program

29.

What is the use of the 'elif' keyword in Python?

a)

To define a function

b)

To handle exceptions

c)

To specify an alternative condition

d)

To import a module

30.

What is the use of the 'else' keyword in Python?

a)

To execute a block of code if a condition is true

b)

To execute a block of code if a condition is false

c)

To execute a block of code after a loop completes

d)

To define a function

31.

What is the use of the 'for' keyword in Python?

a)

To define a function

b)

To create a loop

c)

To handle exceptions

d)

To declare a variable

32.

What is the use of the 'if' keyword in Python?

a)

To define a function

b)

To create a loop

c)

To make a decision based on a condition

d)

To import a module

33.

What is the use of the 'while' keyword in Python?

a)

To define a function

b)

To create a loop that continues until a condition is false

c)

To import a module

d)

To handle exceptions

34.

Fill in the blank: Start all variable names with a ________ letter.

a)

lowercase

b)

uppercase

c)

capital

d)

numeric

35.

Which of the following is a recommendation for naming variables?

a)

A) Use uppercase letters for all variable names

b)

B) Use the names of built-in functions

c)

C) Use meaningful names that are easy to remember

d)

D) Use numbers at the beginning of variable names

36.

What is the name of the Python operator '+'?

a)

Subtraction

b)

Addition

c)

Multiplication

d)

Division

37.

What is the name of the Python operator '-'?

a)

Subtraction

b)

Addition

c)

Multiplication

d)

Division

38.

What is the name of the Python operator '*'?

a)

Subtraction

b)

Addition

c)

Multiplication

d)

Division

39.

What is the name of the Python operator '/'?

a)

Subtraction

b)

Addition

c)

Multiplication

d)

Division

40.

What is the name of the Python operator '//'?

a)

Integer division

b)

Modulo

c)

Exponentiation

d)

Addition

41.

What is the name of the Python operator '%'?

a)

Integer division

b)

Modulo

c)

Exponentiation

d)

Addition

42.

What is the result of 25 / 4? Fill in the blank: 25 / 4 = ___.

a)

6.25

b)

5.5

c)

7

d)

6