My Lemny
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
jroid8@lemmy.world to Programmer Humor@lemmy.ml · 2 years ago

know the features of your language

lemmy.world

message-square
146
link
fedilink
621

know the features of your language

lemmy.world

jroid8@lemmy.world to Programmer Humor@lemmy.ml · 2 years ago
message-square
146
link
fedilink
  • maegul (he/they)@lemmy.ml
    link
    fedilink
    English
    arrow-up
    13
    arrow-down
    1
    ·
    edit-2
    2 years ago

    Python, checking in …

    return (a or b)
    

    Parentheses aren’t necessary, I just prefer them for readability.

    See python documentation on boolean operators for reference. Short story is a or b is an expression that evaluates to a if a is “truthy” else b. “Falsy” is empty strings/containers, 0 and None.

    • juggling_collie@lemmy.ml
      link
      fedilink
      arrow-up
      13
      ·
      2 years ago

      You need to be careful here though. You might not intend for 0 and None to mean the same thing.

      • Bumblefumble@lemm.ee
        link
        fedilink
        arrow-up
        3
        ·
        2 years ago

        So this won’t do the intended thing if a is 0.

        Edit: Sorry I meant to reply to the parent comment, realising now you already write the exact same thing.

        • unalivejoy@lemm.ee
          link
          fedilink
          English
          arrow-up
          3
          ·
          2 years ago

          Also if a is an empty collection or str, or false.

    • unalivejoy@lemm.ee
      link
      fedilink
      English
      arrow-up
      5
      ·
      2 years ago

      There was PEP 505 to add a none-aware operator, but it lost support.

      • maegul (he/they)@lemmy.ml
        link
        fedilink
        English
        arrow-up
        1
        ·
        2 years ago

        That’s a shame, it would have been fitting in “modern” Python along with the walrus and static type system.

Programmer Humor@lemmy.ml

programmerhumor@lemmy.ml

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programmerhumor@lemmy.ml

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 1 user / day
  • 19 users / week
  • 178 users / month
  • 1.26K users / 6 months
  • 0 local subscribers
  • 38.4K subscribers
  • 1.84K Posts
  • 32.4K Comments
  • Modlog
  • mods:
  • AgreeableLandscape@lemmy.ml
  • cat_programmer@lemmy.ml
  • BE: 0.19.13
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org