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 Introducing Tuples Getting to Know Tuples Creating Tuples

Arone Steele
Arone Steele
957 Points

Not getting errors but I am curious

in print = my_tuple is there a difference to doing print(my_tuple) or does it not matter which way I do it?

create_tuple.py
# insert your code here
my_tuple = ('I', 'love', 'python')
print = my_tuple

1 Answer

Travis Alstrand
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Travis Alstrand
Treehouse Project Reviewer

Hey there Arone Steele ! πŸ‘‹

Yes, there is a difference between the two. The way you have shown in your code block, print = my_tuple will actually break your ability to use print afterwards. Here's an explanation:

  1. You create a tuple and store it in my_tuple.

  2. You then reassign the name print so that it no longer refers to Python’s built-in print() function, it now points to your tuple.

  3. After that, if you try to do:

print(my_tuple)

you’ll get an error like:

TypeError: 'tuple' object is not callable

because print is no longer a function, it’s a tuple.

So overall:

  1. print = my_tuple means assign the tuple to the variable named print, overriding the built-in function.

  2. print(my_tuple) means call the print function and pass it my_tuple.

I hope this makes sense!