NEW
Font size
WorksheetsMastering Python Fundamentals
Total questions: 10
Worksheet time: 5mins
What are the basic data types available in Python?
string, number, boolean, collection
int, float, str, bool, list, tuple, set, dict
char, decimal, array, object
integer, double, character, map
How do you declare a variable in Python?
declare variable_name as value
You declare a variable in Python by using the syntax: variable_name = value.
variable_name : value
value = variable_name
What is the difference between a list and a tuple in Python?
Lists are faster than tuples in all operations.
Lists can contain only numbers while tuples can contain any data type.
The main difference is that lists are mutable and tuples are immutable.
Tuples are created using square brackets while lists use parentheses.
Explain the use of 'if', 'elif', and 'else' statements in Python.
'if' is for defining classes, 'elif' is for error handling, and 'else' is for data types.
'if' checks for syntax errors, 'elif' checks for runtime errors, and 'else' checks for logical errors.
'if' checks a condition, 'elif' checks additional conditions, and 'else' executes if none are true.
'if' is used for loops, 'elif' is for defining functions, and 'else' is for importing modules.
What is a for loop and how is it used in Python?
A for loop is a method for creating classes in Python.
A for loop is a type of variable in Python.
A for loop is a control flow statement that allows code to be executed repeatedly for each item in a sequence.
A for loop is used to define functions in Python.
How can you iterate over a dictionary in Python?
Convert the dictionary to a list and iterate over it.
Use a while loop to iterate over the dictionary.
Use recursion to access each key-value pair in the dictionary.
Use a for loop with dict.keys(), dict.values(), or dict.items() to iterate over a dictionary.
What is the purpose of the 'break' statement in a loop?
To continue the loop indefinitely.
To exit a loop prematurely.
To skip the current iteration of the loop.
To pause the loop for a specified time.
How do you handle exceptions in Python using try and except?
Use 'try' to define a function and 'except' to return a value.
Wrap all code in 'except' to catch any exceptions.
Use 'try' to ignore exceptions and continue execution.
Use 'try' to wrap code that may raise an exception, and 'except' to handle the exception.
What is the significance of indentation in Python control flow?
Indentation is optional in Python and has no effect on control flow.
Indentation is used to separate different programming languages in Python.
Indentation is only used for comments in Python code.
Indentation is crucial in Python as it defines the structure and flow of control statements.
How can you use the 'while' loop to create an infinite loop in Python?
while x < 10:
while True:
while False:
while 1:
