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 trialShane Patel
21,619 PointsIs a space between a function's name and the open parenthesis () not allowed?
In challenge 1 of Python Basics it asks to print out a string. In the workspace provided my first attempt came up with an error as I used a space before the open parenthesis i.e.
print ("Hello, Treehouse")
However removing the space worked. I thought spaces were okay as in
x = 2 + 3 rather than the less legible x=2+3
2 Answers
andren
28,558 PointsAs Aryaman alludes to it's pretty common to not place a space between the function name and the parenthesis, if you want your code to be consistent with most other programmers it would be a good idea to adapt that style.
However it's not true that having a space is invalid, Python doesn't care if you have a space or not so the code in your example:
print ("Hello, Treehouse")
Is completely valid Python code, and will run just fine in a real Python shell. The code checker for this challenge is just a bit picky about how your code looks, since it's quite uncommon to have a space it's not something that was taken into account when the checking code was written.
Aryaman Dhingra
3,536 PointsIn programming in general, it is always recommended to space out your code so that it is more readable to anyone who wants to view it, but for a function, the parenthesis always comes right after the function name.
Shane Patel
21,619 PointsThanks Aryaman for your clarification
Shane Patel
21,619 PointsShane Patel
21,619 PointsThanks Andren, nicely explained