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 Collections (Retired) Tuples Stringcases

stringcases.py function returning a tuple with case changes from a string input

Not sure what's wrong with code

stringcases.py
# Handy functions:
# .upper() - uppercases a string
# .lower() - lowercases a string
# .title() - titlecases a string
# There is no function to reverse a string.
# Maybe you can do it with a slice?

def stringcases(string):
  up = string.upper()
  lo = string.lower()
  tit = string.title()
  for itb in string:
    rev = itb[::-1]
  stringcases = (up, lo, tit, rev)
  return stringcases

1 Answer

Kourosh Raeen
Kourosh Raeen
23,732 Points

To reverse the string you don't need the for loop. Just do: rev = string[::-1]

I could have sworn I tried that.. GRRRRrrrrrRRR! Haha

Thanks Kourosh!