1/15
These flashcards cover key concepts and definitions about Python data types, including strings, lists, tuples, dictionaries, and sets to help with exam preparation.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What is a string in Python?
A string is a sequence of characters enclosed in quotes and is immutable.
What does the len() function do in Python?
The len() function returns the number of elements in a string or list.
How can you concatenate two strings in Python?
You can concatenate two strings using the '+' operator.
What is slicing in Python?
Slicing is a powerful feature that allows access to multiple elements of a string, list, or tuple at once.
What are the features of lists in Python?
Lists are ordered, mutable, allow duplicates, and can contain different data types.
What does the append() method do in Python lists?
The append() method adds an element to the end of the list.
Describe the characteristics of tuples.
Tuples are ordered, immutable, allow duplicates, and can be heterogeneous.
What is a dictionary in Python?
A dictionary is an unordered, mutable collection of key-value pairs.
What are sets in Python?
Sets are unordered collections of unique elements, which are mutable and do not allow duplicates.
What method is used to retrieve a value for a specific key in a dictionary safely?
The get() method is used to access a value of a specific key without raising an error if the key doesn't exist.
What is the function of the sort() method in Python lists?
The sort() method sorts the elements of a list in ascending or alphabetical order.
How do you access an individual character in a string?
You can access an individual character in a string using indexing, e.g., s[0] for the first character.
What does the reverse() method do in a list?
The reverse() method flips the order of elements in a list.
How can you check if an element exists in a list or tuple?
You can use a for loop to iterate through the elements and check for existence.
What are the differences between a list and a tuple?
Lists are mutable and allow duplicates while tuples are immutable and can still allow duplicates.
What can be keys in a dictionary?
Keys must be unique and immutable types such as strings, numbers, or tuples.