Python walrus operator := 🦦

  Рет қаралды 24,326

Bro Code

Bro Code

Күн бұрын

Пікірлер: 74
@BroCodez
@BroCodez 4 жыл бұрын
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-px7qu
@Amal-px7qu 2 жыл бұрын
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
@ttrev007 Жыл бұрын
Thank you. This was waaaayyyyyy easier than the other video i watched. very clear and concise
@ojaspednekar
@ojaspednekar 3 жыл бұрын
This is too good. Our bro needs more views and more recognition!!
@therushhourbrothers797
@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
@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
@slowburnertwo Жыл бұрын
Thanks for that I was scratching my head
@anj19911
@anj19911 Жыл бұрын
omg thank you ur amazing
@ligdjumvidja8294
@ligdjumvidja8294 Жыл бұрын
Exactly this my friend. Otherwise the result is only True/false rather than what the string is.
@kristijanlazarev
@kristijanlazarev 11 ай бұрын
Thanks man, i noticed it i was looking for a comment
@itpugil
@itpugil 3 жыл бұрын
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_piFrog
@Dr_piFrog 6 ай бұрын
Good and simple explanation
@Jamie5040
@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
@lelouchlamperouge3676 Жыл бұрын
yeah but it kills the readablity
@ripansharma5259
@ripansharma5259 3 жыл бұрын
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
@reinkdesigns
@reinkdesigns 2 жыл бұрын
@@ЙенФенФыр 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
@joemama6214
@joemama6214 2 жыл бұрын
@@reinkdesigns i tried using your code also but it is still printing in boolean. Pls help.
@kot3en172
@kot3en172 2 жыл бұрын
@@reinkdesigns worked for me, thanks a lot. I was kinda confused why whole list was filled with True
@yangyang6008
@yangyang6008 Жыл бұрын
You are correct! Any thoughts on why the original code gives only booleans? Thanks.
@noraann9140
@noraann9140 2 жыл бұрын
Thanks for the clear explaination!
@rivforest2395
@rivforest2395 Жыл бұрын
very well explained. Many thanks!
@Codenza
@Codenza 3 жыл бұрын
Your explain is perfect bro 👍🏻
@piotrkopcewicz5227
@piotrkopcewicz5227 2 жыл бұрын
great !!
@orfredymelobeltran5237
@orfredymelobeltran5237 3 жыл бұрын
my favorite operator.
@uuhju7004
@uuhju7004 3 жыл бұрын
good video
@shavindasilva
@shavindasilva 2 жыл бұрын
best tutorial :))
@monkeymonkey69696
@monkeymonkey69696 2 жыл бұрын
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)
@databeliever
@databeliever 2 жыл бұрын
"and" is unnecessary, only parentheses are needed. foods = [] while (food := input("> ")) != "quit": foods.append(food)
@Rajkumar_Tripat
@Rajkumar_Tripat 2 жыл бұрын
thanks bro
@beingzero7541
@beingzero7541 3 жыл бұрын
Wow!
@dominikmanaj
@dominikmanaj 2 жыл бұрын
You're AMAZING!!!
@leavesarerandom
@leavesarerandom 3 жыл бұрын
why cant other people explain shit like this? nice and simple, thanks
@tianyaopu9593
@tianyaopu9593 3 жыл бұрын
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-ng2gx
@DucNguyen-ng2gx 3 жыл бұрын
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
@yantic7491
@yantic7491 3 жыл бұрын
@@DucNguyen-ng2gx Thank you bro, it works
@StrangerDanger352
@StrangerDanger352 3 жыл бұрын
@@DucNguyen-ng2gx hey can you pls explain me i did'nt understand
@DucNguyen-ng2gx
@DucNguyen-ng2gx 3 жыл бұрын
@@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
@Chansuri
@Chansuri 2 жыл бұрын
@@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!!!
@Craulback
@Craulback 3 жыл бұрын
Great course so far
@rubenc4696
@rubenc4696 9 ай бұрын
thanks
@ahiamatagabriel5696
@ahiamatagabriel5696 2 жыл бұрын
Thank you
@lw9954
@lw9954 2 жыл бұрын
Ty bro
@kianpetersen751
@kianpetersen751 2 жыл бұрын
GOAT Wooderson line !!
@bekturasanbekov1979
@bekturasanbekov1979 Жыл бұрын
thx 4 vid bro !
@SuperStarEevee
@SuperStarEevee 2 жыл бұрын
Thank you!
@feggy585
@feggy585 Жыл бұрын
That was beautiful 😭
@just_living_
@just_living_ Жыл бұрын
It shows an error cause of the food.append and idk why , can someone help me with this
@IsraelZavala
@IsraelZavala 2 жыл бұрын
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?
@dominikmanaj
@dominikmanaj 2 жыл бұрын
I was about to mention it. It seems like each input statement is stored as True value. Is it intencional?
@dominikmanaj
@dominikmanaj 2 жыл бұрын
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)"
@HomieMusashi
@HomieMusashi 2 жыл бұрын
Big help bro
@suyashagrawal1102
@suyashagrawal1102 2 жыл бұрын
how
@anton-r
@anton-r 2 жыл бұрын
hii, tnx for example !! but in this case the food will contain bool values !! not an user inputs !
@nhannguyenduc6010
@nhannguyenduc6010 2 ай бұрын
:)
@jfmjaco5941
@jfmjaco5941 Жыл бұрын
I get ,true, true, true
@macklykyn8967
@macklykyn8967 2 жыл бұрын
I think to create a list food = list() and food = [] is same bro
@suyashagrawal1102
@suyashagrawal1102 2 жыл бұрын
yeah i think so too hehehehe
@PoorKid1922
@PoorKid1922 3 жыл бұрын
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)
@BharathiChristiano
@BharathiChristiano 3 жыл бұрын
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
@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-oe9vf
@oximas-oe9vf 2 жыл бұрын
The half way point has been REAAAACHED
@giornogiovanna6871
@giornogiovanna6871 Жыл бұрын
:=
@PureTranceSoul
@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?
@EissaAlahdul
@EissaAlahdul 2 жыл бұрын
Thanks!
@OPlutarch
@OPlutarch Жыл бұрын
Thanks!
25 nooby Python habits you need to ditch
9:12
mCoding
Рет қаралды 1,8 МЛН
Is THIS Python's MOST Underrated Operator? (Walrus Operator)
5:45
We Attempted The Impossible 😱
00:54
Topper Guild
Рет қаралды 56 МЛН
Don’t Choose The Wrong Box 😱
00:41
Topper Guild
Рет қаралды 62 МЛН
DAA Paper Analysis I By Nidhi Parashar Ma'am
11:14
GateWay Classes
Рет қаралды 4,6 М.
Let's code a beginner Python BANKING PROGRAM 💰
15:01
Bro Code
Рет қаралды 333 М.
The most controversial Python feature | Walrus operator
8:08
Lex Fridman
Рет қаралды 400 М.
Python super function 🦸
4:45
Bro Code
Рет қаралды 114 М.
Walrus Operator | Python Tutorial
9:23
Portfolio Courses
Рет қаралды 1,6 М.
How I Would Learn Python FAST (if I could start over)
12:19
Thu Vu data analytics
Рет қаралды 725 М.
Please Master These 10 Python Functions…
22:17
Tech With Tim
Рет қаралды 261 М.
Python if __name__ == '__main__' ❓
5:41
Bro Code
Рет қаралды 37 М.
10 Important Python Concepts In 20 Minutes
18:49
Indently
Рет қаралды 456 М.
Python Tutorial: if __name__ == '__main__'
8:43
Corey Schafer
Рет қаралды 2 МЛН