Python Forum
are numeric types passed by value or reference?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
are numeric types passed by value or reference?
#1
Hello,
I would like to know if python passed certain data types by value, and other data types by reference.
Here is an example:

def multiply(myArg):
    myArg = myArg * 2
    return myArg   
y = 5    
multiply(y)
print y # Result is 5, so the variable Y was passed by value?



def appendToList(myList):
    myList.append("luululu")
    
someList = list()    
appendToList(someList)
print someList # Result: ['luululu'], so it was passed by reference?
As you can see the variable y was not modified, whereas the list was modified. So are numeric types passed by value and lists, tuples and other objects passed by reference?

Thank you
Reply


Messages In This Thread
are numeric types passed by value or reference? - by rudihammad - Nov-18-2019, 04:42 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] [listbox] Feed it with dict passed to class? Winfried 3 290 May-13-2024, 05:57 AM
Last Post: Larz60+
  Numeric Enigma Machine idev 9 794 Mar-29-2024, 06:15 PM
Last Post: idev
  How to receive two passed cmdline parameters and access them inside a Python script? pstein 2 433 Feb-17-2024, 12:29 PM
Last Post: deanhystad
Question Numeric Anagrams - Count Occurances monty024 2 1,577 Nov-13-2021, 05:05 PM
Last Post: monty024
  How to get datetime from numeric format field klllmmm 3 2,070 Nov-06-2021, 03:26 PM
Last Post: snippsat
  detecting a generstor passed to a funtion Skaperen 9 3,777 Sep-23-2021, 01:29 AM
Last Post: Skaperen
  Extract continuous numeric characters from a string in Python Robotguy 2 2,726 Jan-16-2021, 12:44 AM
Last Post: snippsat
  how to modify a variable that is passed as parameter StefanL38 2 2,168 Dec-07-2020, 08:39 AM
Last Post: StefanL38
  Pass by object reference when does it behave like pass by value or reference? mczarnek 2 2,624 Sep-07-2020, 08:02 AM
Last Post: perfringo
  How to calculate column mean and row skip non numeric and na Mekala 5 5,101 May-06-2020, 10:52 AM
Last Post: anbu23

Forum Jump:

User Panel Messages

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