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

is this syntax for function is correct def treehouse( ): print("Hello,Treehouse")

is this syntax for function is correct def treehouse( ): print("Hello,Treehouse")

function.py
def treehouse():
  print("Hello,Treehouse")

1 Answer

Tobias Helmrich
Tobias Helmrich
31,603 Points

Hey Rajini,

yes, this code is correct. However you have to write a space before Treehouse to pass the challenge.

So you could write it like this:

def treehouse():
  print("Hello, Treehouse")

But in this challenge you don't even have to define a function for it. You can just print it out directly without a function like this:

print("Hello, Treehouse")

I hope that helps! :)

Anish Walawalkar
Anish Walawalkar
8,534 Points

Hey Tobias, I don't think you can create a function with the function parenthesis, it will throw a SyntaxError. Just tried it out on the python terminal.

Tobias Helmrich
Tobias Helmrich
31,603 Points

Hey Anish, I'm quite sure that it's possible and I also just tried it out on my Terminal - works just fine. Could you show me a screenshot of the terminal with the error?

Hi Tobias, I have edited your answer as you forgot to add your parenthesis. Even if your function does not take any arguments, you must add your parenthesis for it to be a function! Also, when calling your function you must use your parenthesis () as well.

Tobias Helmrich
Tobias Helmrich
31,603 Points

Hey Haider,

oops, I just removed them as I thought I added them accidentally! Haha, I was sure I didn't add them so I already thought I'm going crazy! :) Edit: Forget what I said here, it's not possible to omit the parentheses in a function in Python, sorry for the confusion! :)

Anish Walawalkar
Anish Walawalkar
8,534 Points

whoops, I meant you cannot create/call a function in python without the parenthesis ()

Anish Walawalkar
Anish Walawalkar
8,534 Points

whoops, I meant you cannot create/call a function in python without the parenthesis ()

Hi again Tobias, call me crazy but I know that you can't define a function without using parenthesis. Could you please paste an example of where you think this is possible? Thanks.

Tobias Helmrich
Tobias Helmrich
31,603 Points

Oooops, yes, I'm so sorry guys! I was completely in Ruby mode because I'm going through all the Ruby courses right now and I'm switching between those and the forums! Also because of what Anish said it confused me even more. I'm really sorry, you're absolutely right Haider!

Anish Walawalkar
Anish Walawalkar
8,534 Points

Tobais, you can definitely create and call functions in Ruby without the parenthesis () but you surely can't do it in Python as far as I'm aware.

Haha, I knew I wasn't going crazy! Well at least the problem is resolved now. :)

Tobias Helmrich
Tobias Helmrich
31,603 Points

Sorry again Haider for making you feel like you're crazy! :) Like I said I was in Ruby mode and it made ME crazy, haha! :)

Anish Walawalkar
Anish Walawalkar
8,534 Points

Sorry for confusing you Tobias!! should have proof read my comment. haha!!

Tobias Helmrich
Tobias Helmrich
31,603 Points

Don't worry Anish, I made the initial mistake to cause all the confusion! :)