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 (2015) Python for Beginners Call a function

Shane Patel
Shane Patel
21,619 Points

Is 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

function.py

2 Answers

andren
andren
28,558 Points

As 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.

Shane Patel
Shane Patel
21,619 Points

Thanks Andren, nicely explained

Aryaman Dhingra
Aryaman Dhingra
3,536 Points

In 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
Shane Patel
21,619 Points

Thanks Aryaman for your clarification