+ 7
So, when/why would you want to use an empty tuple or an empty dictionary?
5 Antworten
+ 13
You might want to store the arguments to a function as a tuple, without knowing the structure of the function in advance. If it happens that the function you need to store the parameters for, takes no parameters, you will need to store an empty tuple.
Or another use might be when returning a result. You might need an empty result set, if, for example, the result is blank.
+ 2
when we have to store any value about which we don't know whether it is a string,list,tuple etc.
+ 1
An empty dictionary means assigning a variable to be type dict..... which can later be altered by adding or removing elements. Similar to integer assignment in C/C++.
0
I would use an empty dictionary instead of an empty tuple, or even an empty list, because tuples and string aren't able to be modified, instead of list and dictionaries that you can change the key or the value related to that key, and lists are also capable to be modified any time too.
0
initializing a constant of any sort with zero or as an empty set is often useful when you want a reference from which to compare or reset variables to later in the course of a programs logic flow
I hope that helps!
.