Welcome to the Treehouse Community
Looking to learn something new?
I'm not sure I quite understand this challenge.
I don't think my approach to this challenge is correct. Can someone help explain this to me please.
def stringcases ("single",*args): for string in stringcases print string.uppercase print string.lowercase print string.titlecased print string.reversed return string
Andrew Bruce7,822 Points
The challenge is asking you to take in one string, and output a tuple containing the same string but in different cases (e.g. upper case, lower case etc.).
A tuple is a Python collection which has an unchangeable order and is represented by round brackets () separated by commas. You need to use string methods to alter the string for the first 3 like so -
All uppercase = string.upper()
All lowercase - string.lower()
Titlecased = string.title()
To reverse the string you need to use a slice like so - Reversed = string[::-1]
More on slices here - https://www.pythoncentral.io/how-to-slice-listsarrays-and-tuples-in-python/
Once you have the strings you need to put them into a tuple and return them, you were printing them in your example, this is not the same thing. Returning the value just returns it to the console, if you were to print it you would call the following -
You can shorten this into 2 lines though with the following -
def stringcases(string): return (string.upper(), string.lower(), string.title(), string[::-1])