programming.dev
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
jroid8@lemmy.world to Programmer Humor@lemmy.ml · 1 year ago

know the features of your language

lemmy.world

message-square
146
link
fedilink
623

know the features of your language

lemmy.world

jroid8@lemmy.world to Programmer Humor@lemmy.ml · 1 year ago
message-square
146
link
fedilink
  • maegul (he/they)@lemmy.ml
    link
    fedilink
    English
    arrow-up
    13
    arrow-down
    1
    ·
    edit-2
    1 year 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
      ·
      1 year 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
        ·
        edit-2
        1 year 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
          ·
          1 year ago

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

    • unalivejoy@lemm.ee
      link
      fedilink
      English
      arrow-up
      5
      ·
      1 year 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
        ·
        1 year 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: [email protected]

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.

  • 301 users / day
  • 1.91K users / week
  • 3.17K users / month
  • 9.64K users / 6 months
  • 735 local subscribers
  • 35.9K subscribers
  • 1.77K Posts
  • 38.8K Comments
  • Modlog
  • mods:
  • AgreeableLandscape@lemmy.ml
  • cat_programmer@lemmy.ml
  • BE: 0.19.11
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code
  • join-lemmy.org