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 trialrajinikatukuri
174 Pointsis this syntax for function is correct def treehouse( ): print("Hello,Treehouse")
is this syntax for function is correct def treehouse( ): print("Hello,Treehouse")
def treehouse():
print("Hello,Treehouse")
1 Answer
Tobias Helmrich
31,603 PointsHey 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
8,534 PointsAnish Walawalkar
8,534 PointsHey 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
31,603 PointsTobias Helmrich
31,603 PointsHey 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?
Haider Ali
Python Development Techdegree Graduate 24,728 PointsHaider Ali
Python Development Techdegree Graduate 24,728 PointsHi 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
31,603 PointsTobias Helmrich
31,603 PointsHey 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
8,534 PointsAnish Walawalkar
8,534 Pointswhoops, I meant you cannot create/call a function in python without the parenthesis ()
Anish Walawalkar
8,534 PointsAnish Walawalkar
8,534 Pointswhoops, I meant you cannot create/call a function in python without the parenthesis ()
Haider Ali
Python Development Techdegree Graduate 24,728 PointsHaider Ali
Python Development Techdegree Graduate 24,728 PointsHi 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
31,603 PointsTobias Helmrich
31,603 PointsOooops, 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
8,534 PointsAnish Walawalkar
8,534 PointsTobais, 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.
Haider Ali
Python Development Techdegree Graduate 24,728 PointsHaider Ali
Python Development Techdegree Graduate 24,728 PointsHaha, I knew I wasn't going crazy! Well at least the problem is resolved now. :)
Tobias Helmrich
31,603 PointsTobias Helmrich
31,603 PointsSorry 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
8,534 PointsAnish Walawalkar
8,534 PointsSorry for confusing you Tobias!! should have proof read my comment. haha!!
Tobias Helmrich
31,603 PointsTobias Helmrich
31,603 PointsDon't worry Anish, I made the initial mistake to cause all the confusion! :)