Types Flashcards
What is a sequence type?
A construct that contains a collection of objects.
What is len()?
A function that returns the length of a sequence type.
How do you return an object from a specified index?
Write the sequence name with brackets containing the desired index value.
What value is the first index in a sequence?
0
Can strings be changed?
No.
How is concatenation performed?
Adding two or more strings together with the + operator. Can be done with literals or variables.
What are the Format-string specification types?
s - String: Default.
d - Decimal (integer)
,d - Decimal with commas (integer)
x - hexadecimal
e - exponent notation.
f - fixed point notation
.[x]f fixed point to x spaces.
,.[x]f fixed point with commas.
What is a container?
A construct used to group related values together and contain references to other objects instead of data.
What is a list?
A mutable container created by surrounding a group of variables or literals with brackets.
What is an element?
A single list item.
What is append()?
A function that adds an item to the end of a list.
What is pop(x)?
A function that removes the item at index x in a list.
What is remove(x)?
A function that removes the first item of x value.
What is min(list)?
A function that returns the smallest value in a list.
What is sum(list)?
A function that returns the sum of all items in a list.
What is List.index(x)?
A function that returns the location of an item in a sequence.
What is list.count(x)?
A function that returns the amount of instances of x in a list.
What is a tuple?
It is similar to a list but cannot be changed.
What is a named tuple?
It allows the user to create a simple data type. It is not built-in.
What is a set?
An unordered collection of items. Does not contain multiples of the same item.
Can the index be used in a set?
No.
How is a set created?
By placing a list either between curly braces({[]}), or in the set function (set()).
How is an empty set created.
It must be done using set().
Does list share it’s functions with set?
No. It does have remove and pop, however it has add() instead of append().
What is add(x)?
A function that adds the value x into a set.
What is Set1.update(set2)?
A function that takes the items in one set and adds them to another.
What is clear()?
A function that clears all items from a set.
What is set.intersection(x, y, z)?
A function that returns a set containing the items common between multiple sets.
What is set.union(x, y, z)?
A function that returns a set with all unique items from each set.
What is set.difference(x, y, z)?
A function that returns a set with only the elements that are not found in any of the parenthetical sets.
What is set1.symmetric_difference(set2)?
A function that returns a set with only items that appear in exactly one of set1 or set2.
What is a dictionary?
A collection of keys and values.
What is a key in a dictionary?
An item of any immutable type that is associated with a value.
How is a dictionary created?
By using curly braces surrounding {key : value} pairs.
How are items in dictionaries accessed?
They must be accessed by using the key. Indexing is not an option.
How are items added to a dictionary?
dictionary_name[key] = value
Are dictionaries immutable?
No. The values can be changed the same way items are added, except using keys already present in the dictionary.
How are items removed from dictionaries?
By using the delete keyword del.
del dictionary_name[key].
What is an implicit conversion?
Any conversion between types that the interpreter makes automatically.
What is the dict.keys() function?
A function that returns every key in a dictionary.
What is dict.values()?
A function that returns every value in dict.
What is dict.items()?
A function that returns every key value pairs in dict.
What is the meaning of empty curly brackets in a print function?
It serves as a placeholder for any variables. Print(‘{} is not {}’, x, y)
Output: x is not y