Chapter 4 Loops and Stuff Flashcards
What is a list comprehension?
A line (singular) that does the same thing as a loop
Why would you use a list comprehension?
To make code more efficient
How do you notate a list comprehension, compared to a loop?
Function, for item in list
What is a slice?
Specific group of items in a list
What’s the notation for looping through a slice? What does it mean?
for item in items [:#]; python will print all items up to that number in the list
How do you round variables in f strings?
variable name: .#f
Why round variables in f-strings?
It prevents false accuracies
When round variables in f-strings?
When displaying a data set
What does *= mean? What does the rest of the notation look like if you were multiplying a value by 5
Perform the listed operation on a variable in a list; x *= 5