wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Exploring Python Tokens

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

What is a token in Python?

a)

A token in Python is a function that executes code.

b)

A token in Python is a basic element of the source code, such as keywords, operators, identifiers, and literals.

c)

A token in Python is a data structure for storing values.

d)

A token in Python is a type of variable.

2.

List the three main types of tokens in Python.

a)

modules

b)

keywords, identifiers, literals

c)

variables

d)

functions

3.

What is the purpose of keywords in Python?

a)

To enhance the performance of Python programs.

b)

The purpose of keywords in Python is to define the syntax and structure of the language.

c)

To provide built-in functions for data manipulation.

d)

To allow users to create custom data types.

4.

Identify the keyword used to define a function in Python.

a)

def

b)

procedure

c)

method

d)

function

5.

What symbol is used for addition in Python?

a)

*

b)

+

c)

-

d)

/

6.

Explain the difference between a keyword and an identifier in Python.

a)

Identifiers are used for control flow, while keywords are for data storage.

b)

Keywords can be changed by the programmer, whereas identifiers cannot.

c)

A keyword is a name chosen by the programmer, while an identifier is a reserved word.

d)

A keyword is a reserved word with a predefined meaning, while an identifier is a name defined by the programmer for variables, functions, etc.

7.

How do you create a variable in Python?

a)

value = variable_name

b)

variable_name : value

c)

create variable_name as value

d)

You create a variable in Python by using the syntax: variable_name = value.

8.

What is the role of operators in Python?

a)

Operators in Python manage memory allocation.

b)

Operators in Python are only for mathematical calculations.

c)

Operators in Python are used to define functions.

d)

Operators in Python perform operations on variables and values.

9.

Give an example of a comparison operator in Python.

a)

> (greater than)

b)

== (equal to)

c)

!= (not equal to)

d)

< (less than)

10.

What is the significance of whitespace in Python tokens?

a)

Whitespace is ignored in Python and has no effect on code execution.

b)

Whitespace is significant for separating tokens and ensuring code readability in Python.

c)

Whitespace is mandatory for all Python statements to function.

d)

Whitespace is only used for comments in Python code.

11.

Identify a token that represents a data type in Python.

a)

int

b)

string

c)

float

d)

list

12.

How do you use the 'if' keyword in a Python program?

a)

Use 'if condition:' without indentation for the code block.

b)

Use 'if condition:' followed by an indented block of code to execute if the condition is true.

c)

Write 'if condition then:' to execute the code block.

d)

Use 'if condition' without a colon to check the condition.

13.

What is the output of the expression 5 + 3 in Python?

a)

10

b)

9

c)

6

d)

8

14.

Explain how to use the 'for' keyword in a loop.

a)

Use 'for each item in list:' to loop through a list.

b)

The 'for' keyword is only used for defining functions.

c)

Use 'for variable in sequence:' to iterate over items in a sequence.

d)

You can only use 'for' with numeric ranges.

15.

What is the difference between a logical operator and an arithmetic operator?

a)

Logical operators can only be used in programming; arithmetic operators are used in mathematics.

b)

Logical operators are used for string manipulation; arithmetic operators are for data sorting.

c)

Logical operators deal with boolean values; arithmetic operators deal with numerical values.

d)

Logical operators perform calculations; arithmetic operators compare values.