Walrus Operator Flashcards

1
Q

Walrus operator notation:

A

:=

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does the walrus operator do?

A

Assigns values to variables as part of a larger expression

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Use a print statement with the walrus operator to print cool as true

A

Print(cool:= True)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly