String basics
Lists, Tuples, and Sets
Types
Dictionary basics
Lists, Tuples, and Sets 2
100

what is the purpose of the function len()?

The function len(), which stands for length(variable), is meant to find the number of characters in a variable. 

For example:                         

hollowing = '31/October'

print(len(hollowing))               output: 10

100

The term used to describe where an element is in a list

What is index?

100

The syntax float() is used with this type of data

What are floating point (decimal) numbers?

100

Are dictionary mutable?

Yes. You can change the content of the key and variable.  

100

This is what happens to duplicate elements when put into a set

What is that the duplicates are removed?

200

What function formatting is used to find a character from a variable by knowing its index number? 

Hint: it is the opposite of len()  

print(variable[index])

For example: 

hollowing = '31/October'

print(hollowing[0:2])                         output: 31

* 0:2 =  [0,2)

200

This is the main difference between a tuple and a list

What is that it is not able to be modified?

200

True or false: A list can contain both strings and integers 

What is true?

200

prices = {'apples': 1.99, 'oranges': 1.49} 

print(f"The price of apples is {prices['kiwi']}")

what is the output?  

Traceback (most recent call last):  File "main.py", line 3, in <module>    print(f"The price of apples is {prices['kiwi']}")                                    ~~~~~~^^^^^^^^ KeyError: 'kiwi'

 If it doesn't exist, then you can't use it.

200

Tuples are created like lists except for this one difference

What is parenthesis instead of brackets?

300

how can you output a simple string with a variable?

print('string'/ Varble + 'string' / Varble) 

for Example: 

hollowing = '31/October' 

print('what date is hollowing in 2024: ' + hollowing)

output: what date is hollowing in 2024: 31/October

300

The definition of a set

What is an unordered collection of unique elements?

300

The syntax to convert 1.23 into an integer, and the result of the expression

What is int(1.23) and 1?
300

prices = {'apples': 1.99, 'oranges': 1.49} 

del prices ['apples']

what is the output?

There is no output. we did not have a print statement. 

print(prices)         

output:  {'oranges': 1.49} 

 

300

This must be true about all the elements in a list when using max(list) or min(list)

What is that they all must be the same type?

400

what does the format string do? And how do you construct one?  

The format string is the same as the + function. It allows you to add variables to strings in the same print statement. 

For Example: 

a = '5'

b = '6'

print(f'The sum of {a} and {b} is {a + b}.')   

print('The sum of ' + a + ' and ' + b + ' is ' + a + b +'.')


a = 'abc'

b = 'def'

print(f'The sum of {a} and {b} is {a + b}.')   

print('The sum of ' + a + ' and ' + b + ' is ' + a + b +'.')

400

This is what set1.difference(set2) does

What is that it returns all elements of set1 that are not in set2?

400

The meaning of the term "type" used in computer science 

What is a classification of data that defines how data is stored, and what actions can be done to it?

400

what is the syntax of dictionary? 


Hint: You have a variable that is assigned to key(s) and those key(s) are assigned to a value(element).

Varble = {key:value}  

Letters = 'key' or 'value'

Numbers = NO quotes on key or values 

For example:

jet = {'jet1':'f-35', 'jet2':'f-22',52: 35, 53:42,}

print(jet['jet1'],jet[52],jet['jet2'])

output: f-35 35 f-22

400

The proper code for creating a new set named common_brands that only contains the shared elements between two sets named car_brands and truck_brands

What is common_brands = car_brands.intersection(truck_brands)

or

What is common_brands = truck_brands.intersection(car_brands)

500

lists are mutable [you can modify them after they are created]. How can you construct a list using list methods? 

Hint: remove() or pop() = removes an element from                                         a variable 

        append() = add an element to a variable 

       

variable = elements 

print(Varble)

list method.variable(elements)

print(variable)

For example: 

jet = ['f-12', 'f-22']

print(jet)

jet.append('t-99')

print(jet)

*Notice: [] = lists                   {} = sets  

500

The proper syntax used to return the index of the first element in a list named list_of_numbers whos value matches variable user_num1

What is list_of_numbers.index(user_num1)?

500

10101101 converted from binary to a decimal number

What is 173?

500

How do you access a dictionary entry or a key value using f-string?

 

Hint: Dictionary entries cannot be accessed by indexing.

variable['key'] 

prices = {'apples': 1.99, 'oranges': 1.49} 

print(f"The price of apples is {prices['apples']}")

output: The price of apples is 1.49

(  ${prices['apples']}.:2f  )  for $1.49

500

Use the given tuple to create a named tuple for a person named John who is 175 cm tall, has brown eyes, and black hair. Use an integer for height, and strings for eyecolor and haircolor.

Person = namedtuple('Person' ['height','eyecolor','haircolor'])

What is John = Person(175, 'brown', 'black')


M
e
n
u