Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8387305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:10:29+00:00 2026-06-09T18:10:29+00:00

I have two codes for passing parameters to a function in Python. 1- def

  • 0

I have two codes for passing parameters to a function in Python.
1-

def changeme( mylist ):
   mylist.append([1,2,3,4]);
   print "Values inside the function: ", mylist
   return

mylist = [10,20,30];
changeme( mylist );
print "Values outside the function: ", mylist

2-

def changeme( mylist ):
   mylist = [1,2,3,4]; 
   print "Values inside the function: ", mylist
   return

mylist = [10,20,30];
changeme( mylist );
print "Values outside the function: ", mylist

Why in the first code mylist is passed by reference, and in second code it is passed by value?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:10:30+00:00Added an answer on June 9, 2026 at 6:10 pm

    You need to realize that assignment in python does not operate on the object that is on the left hand side. Assignment creates a new reference to the object on the right hand side and stores that reference in the name on the left hand side. So, in your 1st example you mutate the list which you input and you see that change later. In the 2nd example, inside your function you create a new reference to a list (which is created on the right hand side) and bind that to the local (to the function) variable mylist. Therefore mylist no longer references the object which you input to the function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored proc that I am passing two parameters into. One parameter
I have this code below. As you can see I am passing two variables
I have two similar codes. The first one works as expected. urlpatterns = patterns('',
I have two relatively simple codes. One main activity and one intent service. Main
I have two queries that find both the Zip codes, and the States for
I have these codes for my two tabs. I would like to change the
I have a database that uses codes. Each code can be anywhere from two
I have two bits of code: a form and a jQuery function. My problem
I have two python lists passlist1= [[1, Saturday], [6, Sunday], [12 ,Wednesday], [31, Monday],
I have a method what accepts two parameters and now I need to pass

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.