Linked Questions

28 questions linked to/from Passing values in Python
3362 votes
44 answers
2.2m views

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

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
Swapnil's user avatar
  • 11
0 votes
3 answers
667 views

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) ...
kevin811's user avatar
0 votes
0 answers
413 views

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

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'...
garik f's user avatar
  • 45
1 vote
0 answers
103 views

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 ...
guyd's user avatar
  • 741
1 vote
0 answers
61 views

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(...
NUK's user avatar
  • 11
0 votes
0 answers
60 views

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

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 ...
dave's user avatar
  • 19
10 votes
5 answers
8k views

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 ...
Geo's user avatar
  • 97.7k
4 votes
5 answers
5k views

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 ...
Max's user avatar
  • 271
6 votes
4 answers
804 views

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

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

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 ...
tom's user avatar
  • 1,588
0 votes
1 answer
5k views

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....

15 30 50 per page
1
2