NEW
Font size
WorksheetsExploring Python Fundamentals
Total questions: 20
Worksheet time: 15mins
What are the basic data types in Python?
int, float, str, bool, list, tuple, set, dict
char, byte, array, complex, frozenset, deque, range, memoryview
string, number, object, function, boolean, array, symbol, set
integer, decimal, character, boolean, list, map, tuple, string
How do you create a list in Python?
You create a list in Python using curly braces, e.g., my_list = {} or my_list = {1, 2, 3}.
You create a list in Python by using parentheses, e.g., my_list = () or my_list = (1, 2, 3).
You create a list in Python with the list() function, e.g., my_list = list() or my_list = list(1, 2, 3).
You create a list in Python using square brackets, e.g., my_list = [] or my_list = [1, 2, 3].
What is the output of 5 + 3 * 2?
8
11
9
10
Explain the difference between a list and a tuple in Python.
The main difference is that lists are mutable and tuples are immutable.
Lists are faster than tuples in all operations.
Tuples are used for dynamic data, whereas lists are for static data.
Lists can contain only numbers, while tuples can contain any data type.
How do you check if a number is even in Python?
n - 2 == 0
n % 2 == 0
n % 3 == 0
n / 2 == 1
What is the purpose of the 'if' statement in Python?
To define a function in Python.
To create loops for iteration.
To declare variables in Python.
To execute code conditionally based on a boolean expression.
How do you create a dictionary in Python?
A dictionary in Python is created with parentheses, for example: my_dict = ('key1', 'value1', 'key2', 'value2').
You can create a dictionary in Python using curly braces, like this: my_dict = {'key1': 'value1', 'key2': 'value2'}.
To create a dictionary in Python, use a list format, like this: my_dict = ['key1', 'value1', 'key2', 'value2'].
You can create a dictionary in Python using square brackets, like this: my_dict = ['key1': 'value1', 'key2': 'value2'].
How do you access the first element of a list?
Access the first element with index -1 in a list.
Use index 0 to access the first element of a list.
Retrieve the first element using index 2 of a list.
Use index 1 to access the first element of a list.
What is the output of the expression 10 > 5?
5 >= 10
10 < 5
false
true
What does the 'break' statement do in a loop?
The 'break' statement exits a loop.
The 'break' statement skips the current loop.
The 'break' statement pauses a loop.
The 'break' statement continues to the next iteration.
How do you convert a string to an integer in Python?
int('string')
list('string')
float('string')
str('string')
Who developed Python Programming Language?
Wick van Rossum
Rasmus Lerdorf
Guido van Rossum
Niene Stom
Which of the following is the correct extension of the Python file?
.python
.pl
.py
.p
Which of the following is the correct way to print "Hello, World!" in Python?
print("Hello, World!")
echo "Hello World!"
System.out.print("Hello, World!")
console.log("Hello, World!")
Which data type is used to store a collection of key-value pairs in Python?
List
Tuple
Dictionary
Set
Which data type is used to store textual data in Python?
Integer
Float
Boolean
String
Which of the following is the correct syntax for a for loop in Python?
for(i=0; i<5; i++)
for i in range(5)
for i to 5
foreach i in range(5)
What will be the output of the following code?
0
1
2
1
2
3
0
1
2
3
Infinite loop
Which of the following is used to take input from the user in Python?
read()
scanf()
input()
gets()
What is the output of the following code?
<class 'float'>
<class 'int'>
<class 'str'>
<class 'bool'>
