Can a variable name contain spaces?

I wrote Q 3 vs 19 as a variable for a verse of the quran. It however gave me syntax error after running the program. I rewrote it Q3vs19 taking off the spaces within it, and it went through. Does it imply that having space within it causes the syntax error?

No. A space is a character, and is treated as any other character.

verse_1 = "Q 3 vs 19"
verse_2 = "Q3vs19"


Q 3 vs 19
1 Like

I think you did don’t get my question correctly (so sorry about that), or may be i am the one wrong. You used Q 3 vs 19 and Q3vs19 as a value not variable. I however read that to assign a variable, you cannot allow for space within it. Kindly clarify

variable names can’t have spaces in them.

Variable names must not contain spaces; how would the interpreter know that Q 3 vs 19 is not four variables?

This is exactly my point. Thank you

1 Like