112 Final Study Guide Chapters 8-13 Flashcards
(120 cards)
What are the four collection data types in python?
List (ordered and mutable)
Tuple (unordered and immutable)
Dictonary (stores key:value pairs)
Set (unordered and unindexed)
How do tuples function?
Tuples store multiple values.
They are made up of multiple ordered and indexed elements.
How do tuples differ from lists?
Tuples are immutable (elements are unchangeable)
They are more secure than lists, and are used in situations where security matters.
Tuples also process faster than lists, making them suitable for larger chunks of data.
How are tuples created?
Tuples are created using parentheses, or by seperating values with commas.
You can create empty tuples with an empty pair of parentheses
tuple_1 = (1, 2, 3, 4, 5)
tuple_2 = 1., .5, .25, .125
tuple_3 = ()
What do you need to include when creating a single element tuple?
If you are creating a single element tuple, you must include a comma with the element.
tuple = (1,)
Name some functions, operators, and methods 1you can use on tuples.
len(), max(), min(), sum() functions can all be used on tuples.
+, *, in and not in operators can be used on tuples.
count() and index() methods can be used on tuples.
How do dictionaries work?
Dictionaries store data values in key:value pairs.
The word to you look for is called a key
The word you get back from the dictionary is a value
How do you create dictionaries?
You write dictonaries using curly brackets {}.
key:value pairs are written side by side, each key and value surrounded with quotation marks, and seperated by colons.
dict1 = {“cat” : “aaaaaa”, “dog” : “AAAAAA”, “fish” : “ooooooo”}
What are some rules you must follow when creating keys and values?
Keys must be uniquie, but may be a number or a string.
Keys are case sensitive.
Values can be any data type.
How is the dict() function used?
The dict() function can be used instead of braces to create a dictionary.
x = dict()
How is the items() method used on dictionaries?
You can use the items() method to loop through dictionaries.
Name some methods used on dictionaries.
items () loops through dictionary
update() can add / edit keys and values in a dictionary
keys() get all keys from a dictionary
values() get all values from a dictionary
len(), in and not in can all be used on dictionaries as well.
What are sets?
Sets are an uordered and unindexed collection. Sets contain no duplicate elements, and are written with curly brackets {}
What functions or operations can be used on sets?
len() in, not in are all used on sets.
How can the del keyword be used?
The del keyword can be used to delete elements from collection data types.
How is the copy () method used?
The copy() method creates copies of collection data types.
What are the data type conversion functions?
- int() - converts string, floating point to integer
- float() - converts string, integer to floating point number
- str() - converts integer, float, list, tuple, dict into string
- list() - converts data types into a list
- tuple () - converts data types into a tuple
What are functions?
Functions are blocks of organized, reusable code that together performs a specific task.
Functions only run when called.
Why are functions needed?
Reusability
Functions allow you to define the code a single time, and reuse it as many times as the code needs.
Modularity
Functions allow you to break up long strings of code into smaller steps, allowing you code to be easy to read and maintain.
What 3 groups are functions called from?
Built in Python functions
Functinos imported from modules.
User-defined functions.
How are functions created?
Functions are freated b defining and adding parameters.
def is always put before the function name
The name is followed by a pair of empty brackets () and then a colon :
After this, the body of the function is added on the next line.
When do functions run?
Functions only run when they are called.
Functions are called by writing the name of the function into the code.
def message(): # message is the function name
print(“Enter a value: “) #function body
message()
a = int(input())
Define function parameters and arguments.
Paramaters are the variables listed inside the parentheses next to the function name when defining a function.
Arguments are the values sent to the function when it’s called.
What are the two methods of passing arguments to functions?
Positional argument passing- this commonly used way of passing arguments follows the positions of the paramaterrs and arguments and passes them based on their positions.
Keyword (named) argument passing. The more flexable way of passing arguments. Arguments are passed based on their names.

