wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Understanding Python Basics

Total questions: 12

Worksheet time: 6mins

Name
Class
Date
1.

What are the basic data types in Python?

a)

int, float, str, bool, list, tuple, set, dict

b)

string, number, boolean, collection

c)

char, decimal, array, object

d)

integer, double, character, map

2.

How do you declare a variable in Python?

a)

variable_name : value

b)

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

c)

declare variable_name as value

d)

value = variable_name

3.

What is the difference between '==' and '===' in Python?

a)

In Python, '==' checks for value equality, while '===' does not exist.

b)

'==' checks for type equality, while '===' checks for value equality.

c)

'===' is a valid operator in Python for comparing objects.

d)

Both '==' and '===' are used for strict comparison in Python.

4.

What operator is used for exponentiation in Python?

a)

^

b)

**-

c)

**

d)

**/

5.

How do you append an item to a list in Python?

a)

Use the append() method, e.g., my_list.append(item).

b)

Use the extend() method, e.g., my_list.extend(item).

c)

Use the insert() method, e.g., my_list.insert(item).

d)

Use the add() method, e.g., my_list.add(item).

6.

What method would you use to sort a list in Python?

a)

Use the 'filter()' method

b)

Use the 'sort()' method or the 'sorted()' function.

c)

Use the 'map()' function

d)

Use the 'append()' method

7.

What is the main difference between a list and a tuple?

a)

Lists can contain only numbers, while tuples can contain any data type.

b)

Tuples are used for dynamic data, while lists are for static data.

c)

Lists are faster than tuples in all operations.

d)

The main difference is that lists are mutable while tuples are immutable.

8.

Can a tuple contain mutable objects? Give an example.

a)

No, tuples cannot contain any objects at all.

b)

Yes, a tuple can contain mutable objects. Example: (1, 2, [3, 4]) where [3, 4] is a mutable list.

c)

Yes, but only if the mutable objects are nested within another immutable structure.

d)

No, a tuple can only contain immutable objects.

9.

How do you access a value in a dictionary using its key?

a)

Use dictionary_name[key] to modify the value.

b)

Use dictionary_name[key] to access the value.

c)

Use dictionary_name.get(key) to retrieve the value.

d)

Access the value by calling dictionary_name.key() method.

10.

What method would you use to remove a key from a dictionary?

a)

Use 'remove()' method

b)

Use 'del' or 'pop()' method.

c)

Use 'insert()' method

d)

Use 'add()' method

11.

What is a set in Python and how is it different from a list?

a)

A set is a type of list that allows for indexing.

b)

A set is a collection of unique elements, while a list is an ordered collection that can contain duplicates.

c)

A set can contain duplicate elements, while a list cannot.

d)

A set is an ordered collection, while a list is unordered.

12.

What will be the output of the following code: (1, 2) + (3, 4)?

a)

(1, 2, 4)

b)

(3, 4, 1, 2)

c)

(1, 2, 3, 4)

d)

(1, 3, 2, 4)