what is the purpose of return_string = " " in the code below. Additionally what is happening in line 4 when " " is added to str(x)
Question:
def even_numbers(maximum):
return_string = " "
for x in range(2, maximum+1, 2):
return_string += str(x) + " "
return return_string.strip()
Hi i recently started learning how to code and i dont understand equating empty quotation marks and in some codes adding empty quotation marks to strings like in line 4
Answers:
It’s not empty, it’s a space.
Let’s say you add the following words:
"hello" "friend"
Without the spaces it would become "hellofriend".
With the spaces it would be "hello friend".
def even_numbers(maximum):
return_string = " "
for x in range(2, maximum+1, 2):
return_string += str(x) + " "
return return_string.strip()
Hi i recently started learning how to code and i dont understand equating empty quotation marks and in some codes adding empty quotation marks to strings like in line 4
It’s not empty, it’s a space.
Let’s say you add the following words:
"hello" "friend"
Without the spaces it would become "hellofriend".
With the spaces it would be "hello friend".