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) Tuples Stringcases

Minwook Jeong
Minwook Jeong
2,453 Points

Did I miss something on this challenge question?

Questions: Challenge Task 1 of 1

Create a function named stringcases that takes a single string but returns a tuple of different string formats. The formats should be: All uppercase All lowercase Titlecased (first letter of each word is capitalized) Reversed There are str methods for all but the last one.


my function actually generate how the question wants? any thoughts?

stringcases.py
def stringcases(argument):
    return tuple([str(argument.upper()),
    str(argument.lower()),
    str(argument.capitalize()),
    str(argument[::-1])])


stringcases("hello")

2 Answers

Ari Misha
Ari Misha
19,323 Points

No worries! And i tried with "tuple()" and it wont accept and basically we are returning a tuple anyway so its really weird why wouldnt editor accept it. Maybe its just how these codes are processed behind the scenes, not necessarily an individual's fault. If you'll try in workspaces or PyCharm, it might work. Also, I'd highly recommend you to not add fancy lines of code to your challenge , stick to the instructions in your challenge question. Be simple coz its classy. (:

Ari Misha
Ari Misha
19,323 Points

Hiya Minwook! There are few issues with your code:

  • Firstly, a tuple is a sequence separated by a ","(comma) operator. If you'd like to change something into a tuple just separate the entries by a "comma" and you dont even have to close 'em with parenthesis coz Python knows its a tuple since its separated with a comma.
  • Secondly, you dont have to convert "argument" to a string coz its already a string and returns a "string" as well. So just remove "str()" method. But its not actually an issue.
  • Thirdly, it should be titlecased not caplitalized. So just use "title()" method.

Here is my code for reference:

def stringcases(items):
    return items.upper(), items.lower(), items.title(), items[::-1]
Minwook Jeong
Minwook Jeong
2,453 Points

Thanks Ari, your answer is pretty much helpful for my work but I have a question.. If i want to use 'tuple()', any thoughts???