NEW
Font size
WorksheetsUnderstanding Python Basics
Total questions: 12
Worksheet time: 6mins
What are the basic data types in Python?
int, float, str, bool, list, tuple, set, dict
string, number, boolean, collection
char, decimal, array, object
integer, double, character, map
How do you declare a variable in Python?
variable_name : value
You declare a variable in Python by using the syntax: variable_name = value.
declare variable_name as value
value = variable_name
What is the difference between '==' and '===' in Python?
In Python, '==' checks for value equality, while '===' does not exist.
'==' checks for type equality, while '===' checks for value equality.
'===' is a valid operator in Python for comparing objects.
Both '==' and '===' are used for strict comparison in Python.
What operator is used for exponentiation in Python?
^
**-
**
**/
How do you append an item to a list in Python?
Use the append() method, e.g., my_list.append(item).
Use the extend() method, e.g., my_list.extend(item).
Use the insert() method, e.g., my_list.insert(item).
Use the add() method, e.g., my_list.add(item).
What method would you use to sort a list in Python?
Use the 'filter()' method
Use the 'sort()' method or the 'sorted()' function.
Use the 'map()' function
Use the 'append()' method
What is the main difference between a list and a tuple?
Lists can contain only numbers, while tuples can contain any data type.
Tuples are used for dynamic data, while lists are for static data.
Lists are faster than tuples in all operations.
The main difference is that lists are mutable while tuples are immutable.
Can a tuple contain mutable objects? Give an example.
No, tuples cannot contain any objects at all.
Yes, a tuple can contain mutable objects. Example: (1, 2, [3, 4]) where [3, 4] is a mutable list.
Yes, but only if the mutable objects are nested within another immutable structure.
No, a tuple can only contain immutable objects.
How do you access a value in a dictionary using its key?
Use dictionary_name[key] to modify the value.
Use dictionary_name[key] to access the value.
Use dictionary_name.get(key) to retrieve the value.
Access the value by calling dictionary_name.key() method.
What method would you use to remove a key from a dictionary?
Use 'remove()' method
Use 'del' or 'pop()' method.
Use 'insert()' method
Use 'add()' method
What is a set in Python and how is it different from a list?
A set is a type of list that allows for indexing.
A set is a collection of unique elements, while a list is an ordered collection that can contain duplicates.
A set can contain duplicate elements, while a list cannot.
A set is an ordered collection, while a list is unordered.
What will be the output of the following code: (1, 2) + (3, 4)?
(1, 2, 4)
(3, 4, 1, 2)
(1, 2, 3, 4)
(1, 3, 2, 4)
