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

H Q
H Q
200 Points

def my_function_name(): print("this is the function body") The above function is not working for some reason.

Any advice in getting through this step?

function.py
def my_function_name():
    print("this is the function body")
H Q
H Q
200 Points

The above was an example that I picked up and wanted to know why its not working... finally got there in the end. However, I want to ask why we add a commas in the beginning and end as well as a full stop in print.

example: def function_name(): 'print("Hello, Treehouse")'.

2 Answers

Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points

I am not sure what you mean with commas in the beginning and end as well as a full stop in print

All you have to do in this challenge is:

print("Hello, Treehouse")
H Q
H Q
200 Points

This answer worked. Thanks! Newbie here :) The last time i did it, I used single quotation marks (sorry not commas!) at the beginning and end of print, which surprisingly also worked, hence why i was confused.

Johannes Scribante
Johannes Scribante
19,175 Points

Hi HQ

Well done on finding the answer yourself!

Python needs to be able to identify variable, number and strings. Here is an example that may make things clearer

my_number = 3  # here I assigned my_number to contain the value of 3
my_string = "This is my string."  # here I assigned my_string to have an entire string of characters and spaces

print("Hello there, I am another string.")
#  Hello there, I am another string.
print(my_string) . # in this case the variable my_string's contents will be printed
# This is my string.

Basically what it comes down to is that python uses the " to mark the beginning and end of a string. That is why you need it at the beginning and end of your string and everything you want inside your string should be included in between those ".

Hope it helps :)

H Q
H Q
200 Points

Thanks Johannes! Like the examples. Will definitely keep those in mind for future as I progress through this course.