I really can't justify use of an Empty tuple... a tuple is immutable.. so it should remain empty everytime what can be it's use? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I really can't justify use of an Empty tuple... a tuple is immutable.. so it should remain empty everytime what can be it's use?

Google it.... & find a Sololearn link.. but I can't understand that https://www.sololearn.com/discuss/536893/?ref=app

18th Jul 2017, 4:22 AM
Manoj Mudgal
Manoj Mudgal - avatar
3 Answers
+ 5
The only use I can think of right now is to pass an empty tuple to a method which requires tuples as arguments, to later use it within that function. You're right, though - it can't be changed/modified so it will just stay like this - ()
18th Jul 2017, 5:51 AM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 4
Well, if you have in your code flow a method which outputs a tuple based on some condition and another method, which takes it as an argument and outputs a result as a list, based on the tuple - this second method will take an empty tuple as argument. def tup(a): .... return tuple(a) def lis(b): # where b is tuple .... return list(b[::]).append("OK") Now if b is empty, the code will still work and only output "OK".
18th Jul 2017, 11:04 AM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
0
tuple as argument...& what it does sir?
18th Jul 2017, 10:35 AM
Manoj Mudgal
Manoj Mudgal - avatar