Bobinas P4G
  • Login
  • Public

    • Public
    • Groups
    • Popular
    • People

Conversation

Notices

  1. Ekaitz Zárraga 👹 (ekaitz_zarraga@mastodon.social)'s status on Saturday, 08-Sep-2018 12:10:26 UTC Ekaitz Zárraga 👹 Ekaitz Zárraga 👹
    • jartigag

    @jartigag No.
    Integers are Immutable.

    With:
    b += 1
    you are doing:
    b = 2 + 1
    This is creating a new reference.

    The trick here you need to remember is the = in python doesn't work as in other languages. The = creates a new reference and binds it to the name in the left. So you are creating a reference to the result of 2+1, which is 3.
    So: b = 3 is removing the previous reference to a[1] and changing it to a 3 in the memory.

    Remember this!

    PS: Same happens with tuples they are Immutable.

    In conversation Saturday, 08-Sep-2018 12:10:26 UTC from mastodon.social permalink
    • jartigag repeated this.
    • jartigag (jartigag@mastodon.social)'s status on Saturday, 08-Sep-2018 13:37:17 UTC jartigag jartigag
      in reply to

      @ekaitz_zarraga so in this case the try-except TypeError isn't so wrong, is it? because i want to make a copy if the var is a list or an string, and make a reference to immutable values if the var is an int or a boolean.
      would you do it in a better way, though?

      In conversation Saturday, 08-Sep-2018 13:37:17 UTC permalink

Feeds

  • Activity Streams
  • RSS 2.0
  • Atom
  • Help
  • About
  • FAQ
  • Privacy
  • Source
  • Version
  • Contact

Bobinas P4G is a social network. It runs on GNU social, version 2.0.1-beta0, available under the GNU Affero General Public License.

Creative Commons Attribution 3.0 All Bobinas P4G content and data are available under the Creative Commons Attribution 3.0 license.