+ 4
Empty string
What is the benefit of using empty strings ("") in Python, and why and how are they used?
3 Respuestas
+ 2
Thank you all for your answers.
+ 1
If the string is empty, use the null code.
The code is:
print(null);
0
think of empty string as zero for numbers. for example to find the sum of numbers in a list you initialize sum to zero then iterate over all numbers in the list adding one by one to sum. similarly assume we have a list colors =["red ","green ","blue "] and would like to create a string contains all the elements of colors. we can start by an empty string then keep communicating the elements.
str =""
for c in colors:
str += c
print(str)
the result will be: red green blue