Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics Functions and Looping For Loops

fady mohamed
fady mohamed
5,063 Points

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

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.

Steven Parker
Steven Parker
215,256 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.

fady mohamed
fady mohamed
5,063 Points

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
215,256 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.

Samuel Morgan
Samuel Morgan
2,225 Points

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