+ 2

Can I use spaces in Python strings?

In the playground I can but is it possible in real life? Any advanced Python learners answer is great.

10th Jul 2017, 5:11 AM
Pave
7 odpowiedzi
+ 6
A space is a character like any other (:
10th Jul 2017, 5:50 AM
Maya
Maya - avatar
+ 2
Thank you alot @Maya!!
10th Jul 2017, 5:51 AM
Pave
+ 2
You can even have multiline strings in python ;)
10th Jul 2017, 6:19 AM
Bogdan Sass
Bogdan Sass - avatar
+ 1
But I suppose you cant do a string with only spaces. @Bogdan Sass
10th Jul 2017, 6:24 AM
Pave
+ 1
Yes, you absolutely can. Like Maya said, a space is just a regular character. Try this: mystring=' '
10th Jul 2017, 6:25 AM
Bogdan Sass
Bogdan Sass - avatar
+ 1
Thank you alot!!! @Bogdan Sass
10th Jul 2017, 6:25 AM
Pave
+ 1
Markup languages like HTML tend to have built-in trimming which prevents you from adding too many spaces. Most programming languages reference character codes or bytes. You can add spaces to your heart's desire. Although, what you always need to be careful of with spaces, is that they are not all the same. when you change fonts, so does your kerning change, and thus your entire layout.
10th Jul 2017, 12:25 PM
Jim Tully
Jim Tully - avatar