- 3
And what is the reason of this answer!
while (()): print ("1") else: print ("2")
19 Réponses
+ 2
Just saw, this is a duplicate question:
https://www.sololearn.com/discuss/2288304/?ref=app
+ 2
You put an empty tuple as a condition. They are false, so your loop doesn't run at all.
Else directly after a loop means:
If no break happened in the loop...
Since this is the case, 2 is printed.
0
The else is executed when while is false.
Here to have it maybe easier to understand. While gets executed 3 times, then else.
i = 0
while (i < 3):
print ("1")
i += 1
else:
print ("2")
If you break the loop instead of getting false in while condition the else does not executed.
0
For all collections (Strings, dicts, arrays, tuples, etc.) empty collections are considered as False, non-empty as True.
Btw. an array with an empty tuple is not empty.
https://code.sololearn.com/c93cK6be0wHp/?ref=app
0
((),) this confused me again🤔😟
0
Please describe in proper way and use all aspects
0
Dilyorbek Valijonov type @ and you will see the list of users in this thread and the ones you are related with.
0
Manu_1-9-8-5 please tell the answer
0
Consider that outer parentheses are "ignored". It does not matter how many you place around, if you do not provide values or commas to define other tuples (see also the answer regarding single element tuple by 𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥) they are skipped.
See example printing tuple length:
https://code.sololearn.com/cgXBGFz0YO3W/?ref=app
- 1
Ans is
1
1
1
2
I think if i correct then like