tldr # walrus operator := # new to Python 3.8 # assignment expression aka walrus operator # assigns values to variables as part of a larger expression # happy = True # print(happy) # print(happy := True) # foods = list() # while True: # food = input("What food do you like?: ") # if food == "quit": # break # foods.append(food) foods = list() while food := input("What food do you like?: ") != "quit": foods.append(food)
@Amal-px7qu2 жыл бұрын
you don’t know how much time I spend it to find someone has explain it clearly like you so thank you that was very helpful 🙏
@ttrev007 Жыл бұрын
Thank you. This was waaaayyyyyy easier than the other video i watched. very clear and concise
@ojaspednekar3 жыл бұрын
This is too good. Our bro needs more views and more recognition!!
@therushhourbrothers797 Жыл бұрын
Hey brocode, love the videos :), I have learnt a lot but I think there is a mistake with the example, if you write while food := input("what food do you like?: ") != "quit": foods.append(food). Then it will compare the input to quit thus it will return true to the statement instead it should be like this: while (food := input("what food do you like?: ")) != "quit": foods.append(food)
@treppi1078 Жыл бұрын
agreed! i was also trying to print it, but this made much more sense! still love the work this man is doing, thank you brocode and therushhourbrothers797
@slowburnertwo Жыл бұрын
Thanks for that I was scratching my head
@anj19911 Жыл бұрын
omg thank you ur amazing
@ligdjumvidja8294 Жыл бұрын
Exactly this my friend. Otherwise the result is only True/false rather than what the string is.
@kristijanlazarev11 ай бұрын
Thanks man, i noticed it i was looking for a comment
@itpugil3 жыл бұрын
Understood this explanation better than the other video that I watched. Or maybe because its 3am from where I am, making it hard to grasp the concept. Anyways, great video! Quick and straight to the point!
@Dr_piFrog6 ай бұрын
Good and simple explanation
@Jamie5040 Жыл бұрын
I know the aim wasn’t to make it in as minimal lines as possible but I managed to achieve the same in one line without :=. foods = [food for food in iter(lambda: input("What food do you like: "), 'quit') if food != "quit"]
@lelouchlamperouge3676 Жыл бұрын
yeah but it kills the readablity
@ripansharma52593 жыл бұрын
Hey bro I think you should add brackets after while, becoz otherwise it would not print the list, rather it would result in booleans
@ЙенФенФыр2 жыл бұрын
the code shown in the video works fine without additional brackets
@reinkdesigns2 жыл бұрын
@@ЙенФенФыр try running the code and print foods after you enter quit, it will just print true true true true foods=[] while (food := input('food: ')) != 'quit': foods.append(food) this would be the correct way to write it
@joemama62142 жыл бұрын
@@reinkdesigns i tried using your code also but it is still printing in boolean. Pls help.
@kot3en1722 жыл бұрын
@@reinkdesigns worked for me, thanks a lot. I was kinda confused why whole list was filled with True
@yangyang6008 Жыл бұрын
You are correct! Any thoughts on why the original code gives only booleans? Thanks.
@noraann91402 жыл бұрын
Thanks for the clear explaination!
@rivforest2395 Жыл бұрын
very well explained. Many thanks!
@Codenza3 жыл бұрын
Your explain is perfect bro 👍🏻
@piotrkopcewicz52272 жыл бұрын
great !!
@orfredymelobeltran52373 жыл бұрын
my favorite operator.
@uuhju70043 жыл бұрын
good video
@shavindasilva2 жыл бұрын
best tutorial :))
@monkeymonkey696962 жыл бұрын
your code had a bug print your list the output will be in [true,true,false,] so on you forgot to add "and" foods = list() 👇 while (food := input("enter your food : ")) and food != "q" : foods.append(food) print(foods)
@databeliever2 жыл бұрын
"and" is unnecessary, only parentheses are needed. foods = [] while (food := input("> ")) != "quit": foods.append(food)
@Rajkumar_Tripat2 жыл бұрын
thanks bro
@beingzero75413 жыл бұрын
Wow!
@dominikmanaj2 жыл бұрын
You're AMAZING!!!
@leavesarerandom3 жыл бұрын
why cant other people explain shit like this? nice and simple, thanks
@tianyaopu95933 жыл бұрын
Hi Bro, I was trying to print the "foods" list after appended elements with the walrus operator, but the list I got is like [True, True], basically I added several bool type elements to the list. Would you please let me know how to correct this? Thanks!
@DucNguyen-ng2gx3 жыл бұрын
Hello, I got the same problem as you, but I figured it out: The order that resulted in boolean: input = "pizza" -> "pizza" is not "quit" -> return input as "True" -> While True: add input "True" to foods So we can add brackets () outside (food := input("What food do you like?: ")) to make the order right: input = "pizza" -> While "pizza" is not "quit" -> add input "pizza" to the list
@yantic74913 жыл бұрын
@@DucNguyen-ng2gx Thank you bro, it works
@StrangerDanger3523 жыл бұрын
@@DucNguyen-ng2gx hey can you pls explain me i did'nt understand
@DucNguyen-ng2gx3 жыл бұрын
@@StrangerDanger352 Hello, per my understanding, the code as given in the video first check if the input is "quit" or not (which returns True or False), only then it assigns this boolean value into the variable food. By adding () outside the operator, we make the program assign input to food and only then check whether food is "quit" or not
@Chansuri2 жыл бұрын
@@DucNguyen-ng2gx Thank you I was trying to understand why it was printing out true and not the list this was a good explanation thanks fellow bro!!!
@Craulback3 жыл бұрын
Great course so far
@rubenc46969 ай бұрын
thanks
@ahiamatagabriel56962 жыл бұрын
Thank you
@lw99542 жыл бұрын
Ty bro
@kianpetersen7512 жыл бұрын
GOAT Wooderson line !!
@bekturasanbekov1979 Жыл бұрын
thx 4 vid bro !
@SuperStarEevee2 жыл бұрын
Thank you!
@feggy585 Жыл бұрын
That was beautiful 😭
@just_living_ Жыл бұрын
It shows an error cause of the food.append and idk why , can someone help me with this
@IsraelZavala2 жыл бұрын
when I print the list I get a list full of true statements, like the variable food is being assigned a True value instead of what I'm typing in, has anyone else experienced this?
@dominikmanaj2 жыл бұрын
I was about to mention it. It seems like each input statement is stored as True value. Is it intencional?
@dominikmanaj2 жыл бұрын
This is the solution for the problem I've found in comments "your code had a bug print your list the output will be in [true,true,false,] so on you forgot to add "and" foods = list() 👇 while (food := input("enter your food : ")) and food != "q" : foods.append(food) print(foods)"
@HomieMusashi2 жыл бұрын
Big help bro
@suyashagrawal11022 жыл бұрын
how
@anton-r2 жыл бұрын
hii, tnx for example !! but in this case the food will contain bool values !! not an user inputs !
@nhannguyenduc60102 ай бұрын
:)
@jfmjaco5941 Жыл бұрын
I get ,true, true, true
@macklykyn89672 жыл бұрын
I think to create a list food = list() and food = [] is same bro
@suyashagrawal11022 жыл бұрын
yeah i think so too hehehehe
@PoorKid19223 жыл бұрын
An error occured. Solved by changing this part of codes into: while True: food = input("What food do you like?: ") if food == "quit": break foods.append(food)
@BharathiChristiano3 жыл бұрын
Which can be converted written in lesser character usage: while (food := input("What food do you like?: ")) != "quit": foods.append(food) Code in the video didn't work because he did not use '(' bracket to enclose the walrus operator expression. Thus the code in video evaluates to True and not work as you would expect
@DanTercelify Жыл бұрын
Not a good example because you never use or show the list foods. Therefore, there was no need to save to the list. Also, you don't verify you get the same results with walrus as with traditional approach.
@oximas-oe9vf2 жыл бұрын
The half way point has been REAAAACHED
@giornogiovanna6871 Жыл бұрын
:=
@PureTranceSoul Жыл бұрын
when i run the program and put in food.. it spits out True? how would i make it spit the list and the food i put in it?