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

2 ways, same result, is mine wrong?

In this challenge, I used the following code to print the number of players on the roster

print("There are", len(players), "players on the team")

And Ken used print("There are {} players on the team.".format(len(players)))

They returned the same thing, would my version pose a problem later on? The reason I used it is that I remembered Craig doing it that way in an earlier video in the "lists" lesson.

Thanks

2 Answers

The more you write code the better you become. Later on you will understand that there is not really a wrong way of writing code. Everybody is different and they have preference on how they like to write their code. As long as the code works, it's fine. However, there is a proficient way of writing code, something like "Don't repeat yourself" is one of many factors.

# Both of the lines are fine, and no, your version would not pose a problem at all.
print("There are", len(players), "players on the team")
print("There are {} players on the team.".format(len(players)))

Awesome, good to know. Thank you for the clarity!