Why do we need an empty string. Still confuses me (solved) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why do we need an empty string. Still confuses me (solved)

def num_list(): num ="" for n in "3445": num += n yield num print(list(num_list())) output : ['3', '34', '344', '3445']

5th Sep 2021, 5:05 AM
McAlvin
McAlvin - avatar
3 Answers
+ 3
Because num="" we are defining the data type for num means num data type is a string not a number string + string = stringstring in our example "3" + "4" = 34
5th Sep 2021, 5:10 AM
Pariket Thakur
Pariket Thakur - avatar
+ 1
Arinda Mark Alvin Think of it as an empty container. You can write code which will choose what goes into the container, so the end result will be a collection of items of your choice.
5th Sep 2021, 9:41 AM
Rik Wittkopp
Rik Wittkopp - avatar
0
Ohh okay. Thanks
5th Sep 2021, 5:42 AM
McAlvin
McAlvin - avatar