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 Collections (2016, retired 2019) Slices sillyCase

Mohsan Chaudhry
Mohsan Chaudhry
1,469 Points

Why does the splice need two backslash "//" instead of one (ex: "/")?

Not sure why the 2nd backslash is needed? Having a hard time understanding the syntax.

def sillycase(string):
    return string[:len(string)//2].lower() + string[len(string)//2:].upper()
    """return string[:len(string)/2].lower() + string[len(string)/2:].upper()"""

1 Answer

The / operator will always return a float. The // operator will return an int

print(4 / 2)   # prints 2.0
print(4 // 2)  # prints 2

print(5 / 2)   # prints 2.5
print(5 // 2)  # prints 2