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
  Extract args=, value that was passed to Multiprocessing.Proc object during runtime? haihal 1 738 Dec-08-2024, 07:04 AM
Last Post: Gribouillis
  [SOLVED] [listbox] Feed it with dict passed to class? Winfried 3 1,460 May-13-2024, 05:57 AM
Last Post: Larz60+
  Numeric Enigma Machine idev 9 3,294 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 1,463 Feb-17-2024, 12:29 PM
Last Post: deanhystad
Question Numeric Anagrams - Count Occurances monty024 2 2,373 Nov-13-2021, 05:05 PM
Last Post: monty024
  How to get datetime from numeric format field klllmmm 3 2,886 Nov-06-2021, 03:26 PM
Last Post: snippsat
  detecting a generstor passed to a funtion Skaperen 9 5,584 Sep-23-2021, 01:29 AM
Last Post: Skaperen
  seeking simple|clean|pythonic way to capture {1,} numeric clusters NetPCDoc 6 4,689 Jun-10-2021, 05:14 PM
Last Post: NetPCDoc
  Extract continuous numeric characters from a string in Python Robotguy 2 3,902 Jan-16-2021, 12:44 AM
Last Post: snippsat
  how to modify a variable that is passed as parameter StefanL38 2 2,910 Dec-07-2020, 08:39 AM
Last Post: StefanL38

Forum Jump:

User Panel Messages

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