Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

None Check #7

Open
adamranieri opened this issue Jan 18, 2023 · 0 comments
Open

None Check #7

adamranieri opened this issue Jan 18, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@adamranieri
Copy link

Please read the PEP 572 to see if your proposition is valid or not.

Describe the solution using the Walrus Operator
To ensure that a value returned from a function is not none when used in your code.

nicknames = {"Bill":"Billy", "John":"Jim", "Theodore":"Ted"}

nickname = nicknames.get("Amy")
if nickname:
    print("The nickname is {nickname}")
else:
    print("No nick name")

Describe alternatives you've used
use the walrus operator to check in one line and keep the variable

nicknames = {"Bill":"Billy", "John":"Jim", "Theodore":"Ted"}

if nickname :=  nicknames.get("Amy"):
    print("The nickname is {nickname}")
else: 
    print("No nick name")

Additional context
no

@adamranieri adamranieri added the enhancement New feature or request label Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant