• Pennomi@lemmy.world
      link
      fedilink
      English
      arrow-up
      6
      arrow-down
      1
      ·
      edit-2
      25 days ago

      In Python you can use 🍆 as a variable name.

      Edit: oops, guess I was mistaken, you can use most Unicode but emojis are not valid.

    • ryedaft@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      3
      ·
      25 days ago

      You can use anything that doesn’t start with a digit or punctuation as a variable name (underscore beginning also allowed) unless it’s a keyword.

      • funkless_eck@sh.itjust.works
        link
        fedilink
        arrow-up
        3
        ·
        edit-2
        25 days ago

        _ (sic) as a variable name is often used when a function returns multiple outputs but you only want one

         def my_function:
              return 1, 2, 3
        
         _, two, _ = my_function()
        
        • ryedaft@sh.itjust.works
          link
          fedilink
          English
          arrow-up
          2
          ·
          edit-2
          24 days ago

          Underscore alone is a special variable name and I’m pretty sure anything assigned to it goes straight to garbage collection. Whereas _myvariable is typically used to indicate a “private” class variable or method (Python doesn’t have private so it’s just a convention).

        • Archr@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          22 days ago

          _ can also be used in the python interactive terminal to mean ‘last return value’

          Ie:

          > 'string'
          'string'
          > a = _
          > print(a)
          string