Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics Types and Branching If, Else and Elif

Edward Randall
Edward Randall
1,174 Points

AttributeError: 'NoneType'. What does this mean?

treehouse:~/workspace$ python hello.py
What is your first name? ebby
Hello, ebby
ebby is learning Python
Have a great day {}!
Traceback (most recent call last):
File "/home/treehouse/workspace/hello.py", line 6, in <module>
print("Have a great day {}!").format(first_name)
AttributeError: 'NoneType' object has no attribute 'format'

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 67,636 Points

The .format() is a string method and must be reference by attaching directly to a string with a period or "dot notation". By having the .format outside the print parens, it means running the .format method form the returned value of the print statements. The print command returns the None value. which does not have a .format method. Hence:

The NoneType object [returned from the print statement] has no attribute 'format'

Error messages in Python are surprisingly accurate. It's just that sometimes we don't always grasp their full meaning at first. How I figured it out was by asking myself is "What NoneType object is being referenced and where did it come from?"

Post back if you need more help. Good luck!!