Using "get()" to Return a Default Value from a Python Dict

Using "get()" to Return a Default Value from a Python Dict

Real Python

7 лет назад

38,166 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@jsingh967
@jsingh967 - 28.06.2022 03:28

thanks for that bro

Ответить
@marchanselthomas7393
@marchanselthomas7393 - 27.02.2022 15:04

great tutorial

Ответить
@GDisclaimer
@GDisclaimer - 27.12.2021 18:15

Thanks for the lesson, but i think, f-strings more pretty

Ответить
@Anonymous-1011
@Anonymous-1011 - 03.08.2021 09:24

It was nice the way you took us to the climax. It was smooth.

Ответить
@eloypereyra919
@eloypereyra919 - 05.07.2021 10:22

thank you so much

Ответить
@xesiusprime9360
@xesiusprime9360 - 16.04.2021 06:06

awesome vid thanks

Ответить
@carloslara1979
@carloslara1979 - 12.12.2020 10:36

How do you use it in nested dictionaries?

Ответить
@MechF29
@MechF29 - 25.09.2020 20:12

What is the IDE hes using?

Ответить
@programmerrdai
@programmerrdai - 15.05.2020 16:02

Great content....

Ответить
@ToriKo_
@ToriKo_ - 09.05.2020 12:44

Okay so the last version

def greeting(user_id):
return “Hi %s!” % name_for_user_id.geet(user_id, “there”)

doesn’t have to deal with a ‘membership check’ and you don’t have to write an exception block, and it’s understandable.

Also, String substitution is the name for the weird %s.

Ответить
@KittyFisouw
@KittyFisouw - 26.04.2020 19:41

That was very useful thank you!

Ответить
@catalinacruz366
@catalinacruz366 - 08.10.2019 16:05

Thanks !

Ответить
@konjis1
@konjis1 - 04.04.2019 06:53

how can you print the key though instead of the value?

Ответить
@qq47296698
@qq47296698 - 21.10.2018 18:40

thanks so much, very clear to understand the .get().

Ответить
@cryptochef70
@cryptochef70 - 23.08.2018 11:51

Fuck me! Never heard anyone pronounce Python so annoyingly.

PIE THORRRN....

Ответить
@pwood22
@pwood22 - 09.04.2018 19:09

Hi Dan, great tip! I like the way you developed the thought process leading to the solution. What python console are you using? I love the code completion feature that I don't have from within terminal or iTerm.

Ответить
@arpitj07_
@arpitj07_ - 04.12.2017 20:02

why isn't the return statement working in sublime text ?
i copied the same code it doesnt gives any output nor any error. Though it runs on python.

Ответить
@justgivemethetruth
@justgivemethetruth - 30.05.2017 01:11

Why is it not good style to use a membership check?
I'm assuming because every time it executes it has to check through a whole, what might be megabytes or ids for this check .... but that is not really a "style" think is it? It is more of an efficiency thing?

But, even with the key error thing you still end up checking all the keys, no? But at least, not more than once.

Great video by the way, super to the point and efficient! thumbs up

Ответить
@MrNagios
@MrNagios - 24.03.2017 17:44

Hi, you had to finish with setdefault method, but it still cool presentation of the subject. Thanks!

Ответить
@JovaniMoura
@JovaniMoura - 12.03.2017 21:38

I'm a Brazilian and I really enjoyed this video. Nice work!

Ответить
@baderalmutairi6915
@baderalmutairi6915 - 13.09.2016 16:59

Thank you for providing easy and smooth example ..Thanks.

Ответить