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 trialfady mohamed
5,972 PointsAre 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
231,248 PointsSpaces 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.
Podrig Leoghain
5,094 PointsTo add to what Steven Parker wrote, the space in "Happy Birthday" will print because it is in a string.
Samuel Morgan
2,226 PointsYeah, the space is included as it is inside the string. print ("S S") would be: S S
fady mohamed
5,972 Pointsfady mohamed
5,972 PointsThanks 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
231,248 PointsSteven Parker
231,248 PointsIn 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.