[issue36393] python user define function is replacing variable value

2019-03-21 Thread Hardik


New submission from Hardik :

I have created function "listappend():"with two arguments.Function can append 
list value with each function call and return updated value. I am trying to 
store this updated value into variable which I can but when I call listappend() 
to update it changes the stored variable value every time when I call a 
function.

You can see in below given example, list value is [10,20,30] and I have stored 
with value 40 in varible x.
so now x is [10,20,30,40]. I called function with new list value with [50] now 
it become [10,20,30,40,50]
and the value of x is replaced with new value.  Even if you store x into a new 
variable and call listappend() again with new value then it will replace the 
value of new variable.  
 
>>> def listappend(a,list=[]):  
... list.append(a)
... return list
... 
>>> listappend(10) 
[10]
>>> listappend(20) 
[10, 20]
>>> listappend(30) 
[10, 20, 30]
>>> x = listappend(40) 
>>> print(x)
[10, 20, 30, 40]
>>> y = listappend(50) 
>>> print(y)
[10, 20, 30, 40, 50]
>>> z = listappend(60) 
>>> print(z)
[10, 20, 30, 40, 50, 60]
>>> print(x)  
[10, 20, 30, 40, 50, 60]
>>> print(y)  
[10, 20, 30, 40, 50, 60]
>>> print(z)
[10, 20, 30, 40, 50, 60]
>>>

--
components: macOS
files: logical Er
messages: 338568
nosy: HardikPatel, ned.deily, ronaldoussoren
priority: normal
severity: normal
status: open
title: python user define function is replacing variable value
type: enhancement
versions: Python 3.7
Added file: https://bugs.python.org/file48227/logical Er

___
Python tracker 
<https://bugs.python.org/issue36393>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36442] Different ValueError for the same operation in List and Tuple

2019-03-26 Thread Hardik


New submission from Hardik :

I am curious why ValueErrors are different in List and Tuple when I try to get 
an index.  ValueError of a list returns in well format with actual argument 
"ValueError: 'ITEM' is not in list", whereas tuple returns something like this 
"ValueError: tuple.index(x): x not in tuple". 
I think List and Tuple both are calling same index() method then why it is 
raising different ValueErrors? 
>>> jframe_li
['Angular', 'React', 'Vue.js', 'Ember.js', 'Mereor', 'Node.js', 'Backbone.js']
>>> jframe_tu
('Angular', 'React', 'Vue.js', 'Ember.js', 'Mereor', 'Node.js', 'Backbone.js')
>>> jframe_li.index('React')
1
>>> jframe_tu.index('React')
1
>>> jframe_li.index('react')
Traceback (most recent call last):
  File "", line 1, in 
ValueError: 'react' is not in list

>>> jframe_tu.index('react')
Traceback (most recent call last):
  File "", line 1, in 
ValueError: tuple.index(x): x not in tuple

--
components: Tests
messages: 338906
nosy: HardikPatel
priority: normal
severity: normal
status: open
title: Different ValueError for the same operation in List and Tuple
type: behavior
versions: Python 3.7

___
Python tracker 
<https://bugs.python.org/issue36442>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com