

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 are arguments passed by value or by reference in Python?
Python uses a mechanism, which is known as "Call-by-Object", sometimes also called "Call by Object Reference" or "Call by Sharing"
If you pass immutable arguments like integers, strings or tuples to a function, the passing acts like Call-by-value. It's different, if we pass mutable arguments.
All parameters (arguments) in the Python language are passed by reference. It means if you change what a parameter refers to within a function, the change also reflects back in the calling function.
Example
student={'Archana':28,'krishna':25,'Ramesh':32,'vineeth':25} def test(student): new={'alok':30,'Nevadan':28} student.update(new) print("Inside the function",student) return test(student) print("outside the function:",student)
Output
Inside the function {'Archana': 28, 'krishna': 25, 'Ramesh': 32, 'vineeth': 25, 'alok': 30, 'Nevadan': 28} outside the function: {'Archana': 28, 'krishna': 25, 'Ramesh': 32, 'vineeth': 25, 'alok': 30, 'Nevadan': 28}
- Related Questions & Answers
- How to pass arguments by reference in Python function?
- Is java pass by reference or pass by value?
- How to pass arguments by reference in a Python function?
- Is JavaScript a pass-by-reference or pass-by-value language?
- Pass by reference vs value in Python
- How to pass arguments by value in Python function?
- Pass by reference vs Pass by Value in java
- Call by value and Call by reference in Java
- Difference between Call by Value and Call by Reference
- Which one is better in between pass by value or pass by reference in C++?
- Describe pass by value and pass by reference in JavaScript?
- Differences between pass by value and pass by reference in C++
- What is Pass By Reference and Pass By Value in PHP?
- Sort Python Dictionaries by Key or Value
- How command line arguments are passed in main method in C#?
Advertisements