Aug-09-2018, 09:09 AM
Hi Viewer,
Got a query on function default arguments.
The same code when used a tuple instead of an integer,
Integers and tuples both being immutable types, why does python differentiate between the both when it comes to default arguments? Thanks in advance.
Thanks,
Kiran.
Got a query on function default arguments.
i = 10 def fun(l = 10): if i is l: print('mathced') else: print('not matched') fun()The above code would output "matched".
The same code when used a tuple instead of an integer,
i = (1, 2, 3) def fun(l = (1, 2, 3)): if i is l: print('matched') else: print('not matched') fun()prints 'not matched'.
Integers and tuples both being immutable types, why does python differentiate between the both when it comes to default arguments? Thanks in advance.
Thanks,
Kiran.