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

Function in python

Hi, In this code below. I dont understand what //4 means on line four. What different will it make if i change from //4 to //2? def yell(text): text = text.upper() number_of_characters = len(text) result = text + "!" * (number_of_characters //4) print(result)

yell("You are doing great") yell("Dont forget to ask for help") yell("Dont repeat yourself. Keep things DRY")

2 Answers

Steven Parker
Steven Parker
231,198 Points

In Python, // is the "floor division" operator. So the // 4 means "divide by four and keep only the integer part of the result".

So if you changed the 4 to a 2, you would end up with about twice as many exclamation points added to the end of the text.

So, for example, yell("You are doing great") would return:

  • You are doing great!!!!:point_left: with the original code
  • You are doing great!!!!!!!!! :point_left: with the 4 changed to a 2

Thanks Steven, Now i understand much better.