Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
output values change
#2
a and b are just names used to reference objects. The names are of no importance here.

a references an int object. Int objects are immutable, they cannot change. 2 is always 2, and you cannot change 2 to 3. You can reassign a variable to reference a different int object. num first referenced 2, then was assigned to reference 3. The only relationship between a and num is that the int object referred to by a was passed to a function as the argument num. The variables a and num know nothing about each other. Even if you rewrote the function to look like below.
def something(a,b):
    a=3
    b[0]=3
The function arguments a and b have no relationship with the global variables a and b. They just happen to have the same names.

b references a list. Lists are mutable, they can be changed. Your function changes the list object so it holds the int object 3 instead of 2.

The "value of" a and b do not change in your program. a always refers to the int object 2, and b always refers to the same list object.
akbarza likes this post
Reply


Messages In This Thread
output values change - by akbarza - Oct-17-2023, 10:14 AM
RE: output values change - by deanhystad - Oct-17-2023, 11:09 AM
RE: output values change - by akbarza - Oct-18-2023, 07:58 AM
RE: output values change - by deanhystad - Oct-18-2023, 12:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Find a specific keyword after another keyword and change the output sgtmcc 5 924 Oct-05-2023, 07:41 PM
Last Post: deanhystad
  Rain sensor output only on change Pete6 3 2,104 May-11-2022, 10:36 PM
Last Post: Pete6
  change numerical values to categorical names JoeOpdenaker 3 2,995 Nov-02-2020, 01:32 PM
Last Post: DeaD_EyE
  change array column values without loop khalidreemy 2 3,885 May-05-2019, 09:05 AM
Last Post: DeaD_EyE
  Change Text Color Output in Python bluethundr 2 8,790 Mar-06-2019, 10:23 PM
Last Post: bluethundr
  Confusing output from 2to3 about what files need change Moonwatcher 1 4,876 Dec-30-2018, 04:07 PM
Last Post: Gribouillis
  Change output of cells. Hoogoo 2 2,658 Nov-19-2018, 12:47 AM
Last Post: Larz60+
  Change values in string multiline DavidFernandez 4 3,172 Aug-26-2018, 08:09 PM
Last Post: buran
  Change the output window size and display area issac_n 0 2,290 Apr-13-2018, 04:41 AM
Last Post: issac_n
  Change Windows Sound Output Device with Python delfar 1 10,407 Sep-15-2017, 12:11 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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