Python Forum
Why doesn't list require global keyword?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why doesn't list require global keyword?
#7
(Jan-15-2024, 01:35 AM)johnywhy Wrote: Unclear. x is mutable. I can say
x+=1

It's always good idea to read documentation:

3. Data model > 3.1.1. Objects, values and types:

Quote:The value of some objects can change. Objects whose value can change are said to be mutable; objects whose value is unchangeable once they are created are called immutable. (The value of an immutable container object that contains a reference to a mutable object can change when the latter’s value is changed; however the container is still considered immutable, because the collection of objects it contains cannot be changed. So, immutability is not strictly the same as having an unchangeable value, it is more subtle.) An object’s mutability is determined by its type; for instance, numbers, strings and tuples are immutable, while dictionaries and lists are mutable.

From glossary:

immutable:

Quote:An object with a fixed value. Immutable objects include numbers, strings and tuples. Such an object cannot be altered. A new object has to be created if a different value has to be stored. They play an important role in places where a constant hash value is needed, for example as a key in a dictionary.

mutable:

Quote:Mutable objects can change their value but keep their id(). See also immutable.
johnywhy likes this post
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
RE: Why doesn't list require global keyword? - by perfringo - Jan-15-2024, 08:36 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Extending list doesn't work as expected mmhmjanssen 2 282 May-09-2024, 05:39 PM
Last Post: Pedroski55
  Find a specific keyword after another keyword and change the output sgtmcc 5 957 Oct-05-2023, 07:41 PM
Last Post: deanhystad
  Why doesn't calling a parent constructor work with arbitrary keyword arguments? PurposefulCoder 4 1,047 Jun-24-2023, 02:14 PM
Last Post: deanhystad
Question Keyword to build list from list of objects? pfdjhfuys 3 1,690 Aug-06-2022, 11:39 PM
Last Post: Pedroski55
  How to make global list inside function CHANKC 6 3,231 Nov-26-2020, 08:05 AM
Last Post: CHANKC
  Pattern Require Last Line Print() why? Harshil 4 2,517 Aug-08-2020, 04:54 PM
Last Post: Harshil
  Require Some Suggestions gouravlal 2 1,949 Jul-27-2020, 06:14 AM
Last Post: gouravlal
  search binary file and list all founded keyword offset Pyguys 4 2,883 Mar-17-2020, 06:46 AM
Last Post: Pyguys
  Where to put the global keyword when assigning variables outside a function? new_to_python 8 3,142 Feb-09-2020, 02:05 PM
Last Post: new_to_python
  Global variable does not seem to be global. Columbo 6 3,813 Jul-15-2019, 11:00 PM
Last Post: Columbo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020