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 trialVedang Patel
7,114 PointsI didn't understand what the task wants us to do
Please help me this is what it asks us to do
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 is capitalized) Reversed There are str methods for all but the last one.
2 Answers
Ronit Mankad
12,166 PointsHi Vedang! The question is simple. We have to create a function named stringcases which takes a string as a argument and returns a tuple with following String in:
- uppercase format. 2.lowercase format. 3.Titlecase format(only first letter capital) 4.And reversed.
The execution is simple:
def stringcases(st):
my_list = list(st)
string_reversed = my_list[-1::-1]
my_tuple = st.upper(),st.lower(),st.title(), ''.join(string_reversed)
return my_tuple
for reversing the string, we first create a list with letters of the string, and then reverse it using Slices, and then join the letters together using ''.join(my_list) function. We put all this into a tuple and return the tuple.
Hope you understand this, if not feel free to ask anytime!
Ronit Mankad
12,166 PointsMy_list = list(st) Here we are creating a list by iterating a string.
Eg: my_list = list("Hello") Will be my_list= ['H','e','l','l','o']