Walrus Operator Flashcards
1
Q
Walrus operator notation:
A
:=
2
Q
What does the walrus operator do?
A
Assigns values to variables as part of a larger expression
3
Q
Use a print statement with the walrus operator to print cool as true
A
Print(cool:= True)
4
Q
Use the walrus operator to make this piece of code more efficient:
Foods= list()
While True:
food= input(“What food do you like”)
If food=“quit”
Break
Foods.append(food)
A
Foods = list()
while food := input(“what food do you like”) != “quit”:
Foods.append(food)