Empty string | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Empty string

What is the benefit of using empty strings ("") in Python, and why and how are they used?

18th Jul 2018, 7:05 PM
arbaaz
3 Answers
+ 2
Thank you all for your answers.
21st Jul 2018, 3:16 PM
arbaaz
+ 1
If the string is empty, use the null code. The code is: print(null);
18th Jul 2018, 8:18 PM
program
program - avatar
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
19th Jul 2018, 2:06 PM
alasidig
alasidig - avatar