- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to pass arguments by reference in Python function?
In Python, function arguments are always passed by reference. This can be verified by checking id() of factual, formal arguments and returned object
def foo(x): print ("id of received argument",id(x)) x.append("20") return x a = ["10"] print ("id of argument before calling function",id(a)) b = foo(a) print ("id of returned object",id(b)) print (b) print (a)
The id() of a, x inside foo() and b are found to be same.
id of argument before calling function 1475589299912 id of received argument 1475589299912 id of returned object 1475589299912
- Related Articles
- How to pass arguments by reference in a Python function?
- How to pass arguments by value in Python function?
- How are arguments passed by value or by reference in Python?
- Pass by reference vs value in Python
- How to pass arrays as function arguments in JavaScript?
- Pass by reference vs Pass by Value in java
- How to pass an array by reference in C++
- Describe pass by value and pass by reference in JavaScript?
- Is java pass by reference or pass by value?
- What is Pass By Reference and Pass By Value in PHP?
- Differences between pass by value and pass by reference in C++
- Pass an integer by reference in Java
- Is JavaScript a pass-by-reference or pass-by-value language?
- How do you pass objects by reference in PHP 5?
- How to pass individual members of structure as arguments to function in C language?

Advertisements