Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics Functions and Looping For Loops

Are Spaces Considered Letters in Python?

I know spaces are considered characters so that it is counted when using the len() method for e.g.

However are they also considered letters? Are there any cases where they aren't?

3 Answers

Steven Parker
Steven Parker
231,275 Points

Spaces are characters but not letters. The term "letters" (or "alpha characters") refers to "a" to "z" or "A" to "Z".

Offhand, I can only think of this distinction being used in Regular Expressions.

Thanks Steven, I'm just asking because with the code in this video the spaces are also output when using for letters in. I assumed it would just display "HAPPYBIRTHDAY", however it included the space and the exclamation mark. Am I missing something?

Steven Parker
Steven Parker
231,275 Points

In the video code, "letter" is just a variable name and has no special significance. You could substitute "noodle" and the program would perform the same.

Podrig Leoghain
Podrig Leoghain
5,094 Points

To add to what Steven Parker wrote, the space in "Happy Birthday" will print because it is in a string.

Samuel Morgan
Samuel Morgan
2,226 Points

Yeah, the space is included as it is inside the string. print ("S S") would be: S S