What is a tuple in Python?
An ordered and immutable collection of elements used to group related data together.
How are tuples written in Python?
As comma-separated elements enclosed in parentheses ().
What types of data can tuples contain?
Tuples can include strings, integers, floats, or even other tuples.
How do you access elements in a tuple?
By using positive or negative indexing.
What operations can you perform on tuples?
Combining, concatenating, and slicing.
Why are tuples considered immutable?
They cannot be changed after creation; to modify them you must create a new tuple.
What is tuple nesting?
When a tuple contains other tuples or complex data types.
How do you access elements in a nested tuple?
By using multiple levels of indexing (e.g., t[1][0]).
What is a list in Python?
An ordered and mutable collection of items that can hold different data types.
How are lists written in Python?
As comma-separated elements enclosed in square brackets [].
What property makes lists similar to tuples?
Both are ordered sequences of elements.
What makes lists different from tuples?
Lists are mutable, while tuples are immutable.
What types of data can a list contain?
Strings, integers, floats, and even other lists (nested lists).
How do you access elements in a list?
By using positive or negative indexing.
What happens when you concatenate or append a list?
The same list is modified, not a new one created.
What operations can you perform on lists?
Adding, deleting, splitting, concatenating, and slicing.
What separates elements in a list?
Commas (delimiters).
What is aliasing in lists?
When multiple names refer to the same list object in memory.
How do you clone a list?
By creating a copy (e.g., list_copy = original_list[:]) to avoid aliasing.
What is a dictionary in Python?
A collection of key-value pairs for flexible data storage and retrieval based on unique keys.
How are dictionaries written in Python?
Using curly brackets {} with key-value pairs separated by colons.
What are the rules for dictionary keys?
Keys must be immutable and unique.
Can dictionary values be duplicated?
Yes, values may be duplicated and can be mutable or immutable.
How do you separate key-value pairs in a dictionary?
By commas between each pair.