Linked Questions
28 questions linked to/from Passing values in Python
3362
votes
44
answers
2.2m
views
How do I pass a variable by reference?
I wrote this class for testing:
class PassByReference:
def __init__(self):
self.variable = 'Original'
self.change(self.variable)
print(self.variable)
def change(self, ...
0
votes
1
answer
6k
views
how pass-by-reference and pass-by-value works in python [duplicate]
I thought I understood python's pass-by-reference and pass-by-value processing...
can anyone explain what is the difference between pass-by-reference and pass-by-value in python
0
votes
3
answers
667
views
Changing the passed-in list within a function [duplicate]
Consider the Python code below:
def change_list(in_list):
in_list = [1,2,3]
def change_list_append(in_list):
in_list.append(7)
my_list = [1,2,3,4,5,6]
change_list(my_list)
print(my_list)
...
0
votes
0
answers
413
views
How is the behavior of local/global mutable object different from immutable object in python? [duplicate]
Scenario 1 : Mutable object like list
def a(l):
l[0] = 1
print("\nValue of l = {0} in a()".format(l))
def b(l):
l = l + [9]
print("\nValue of l = {0} in b()".format(l))
l = [0]
a(l)...
0
votes
1
answer
94
views
Python value in dictionary changed without update [duplicate]
I try this simple code:
def chage_value(dict, key):
dict[key] = 123
return dict
my_dict = {'a': 1, 'b': 2}
print(my_dict)
chage_value(my_dict, 'a')
print(my_dict)
This gives me output:
{'a'...
1
vote
0
answers
103
views
Python- unexplained behaviour of datetime [duplicate]
I'm trying to understand a weird behavior when using datetime inside python's dictionary. Code below is written to explain. I expected that the example of variable a and b will act the same as self.x ...
1
vote
0
answers
61
views
Why list in python do that? [duplicate]
I try to create the list of object with some attributes like this.
info.py
import numpy as np
class MapInfo(object):
"""docstring forInfomation."""
def __init__(self, arg):
super(...
0
votes
0
answers
60
views
How IDE know that variable? [duplicate]
def y(v0,t):
g=9.81
return v0*t - 0.5*g*t**2
v0 = 5
time = 0.6
print(y(v0,time))
in this code how does the computer understand the time variable even though the t variable is used in the code?
I ...
0
votes
0
answers
36
views
what is the reason behind changing values of python list without explicit modification? [duplicate]
def isCyclicUtil(graph,v,visit,parent):
visit[v]= True
for i in graph[v]:
if visit[i]==False :
if(isCyclicUtil(graph,i,visit,v)):
return True
...
10
votes
5
answers
8k
views
Are Python's bools passed by value?
I sent a reference to a bool object, and I modified it within a method. After the method finished its execution, the value of the bool outside the method was unchanged.
This leads me to believe that ...
4
votes
5
answers
5k
views
C# vs Python argument passing
What are the main differences, if any, of Python's argument passing rules vs C#'s argument passing rules?
I'm very familiar with Python and only starting to learn C#. I was wondering if I could think ...
6
votes
4
answers
804
views
How Does Calling Work In Python? [duplicate]
For a project I'm working on, I'm implementing a linked-list data-structure, which is based on the idea of a pair, which I define as:
class Pair:
def __init__(self, name, prefs, score):
...
2
votes
5
answers
496
views
Why are lists linked in Python in a persistent way?
A variable is set. Another variable is set to the first. The first changes value. The second does not. This has been the nature of programming since the dawn of time.
>>> a = 1
>>&...
2
votes
6
answers
347
views
python is stealing objects from me
Well I'm just learning Python and I'm experiencing some strange behavior. I guess that garbage collector is responsible for that but I'm not sure.
SORRY LADS I MESSED UP THE QUESTION
I wanted ...
0
votes
1
answer
5k
views
Python toggle boolean with function
I'm trying to toggle a boolean with the help of a seperate function.
If my research is correct, there are no pointers in Python (I'm starting to learn it right now) so I'm unsure how to fix this issue....