On 12 May 2011 12:34, Alex Smith <alexsmith24...@yahoo.com> wrote: > Hi All, > > I just joined this list and am really new to python. I have an assignment > to create a function with (a_string, width) which returns the a_string with > all the lower case characters changed to upper case characters and vice > versa and centered; was wondering if someone could point me in the right > direction. I am not just asking for the answer but just need a few tips to > get started. So far I do know I should use the dir(str) > and do not quite understand what the "width" option is used for.... > > I think you're missing the point about the suggestion to use dir() -- as per the help you yourself retrieved, dir returns "an alphabetized list of names comprising (some of) the attributes of the given object, and of attributes reachable from it..." The suggestion to do dir(str) was intended as a way to learn about how string objects work in Python, not that it should be used directly in the source code of your solution.
For example, "dir(str)" lists an interesting attribute (in this case a method) called "swapcase"... now investigating this by doing "help(str.swapcase)" you get: >>> help(str.swapcase) Help on method_descriptor: swapcase(...) S.swapcase() -> string Return a copy of the string S with uppercase characters converted to lowercase and vice versa. Sounds relevant to your goals. ;) As for the "width" question, think about the requirement to "center" the string. Centered with reference to what? How are you going to center something if you don't know how wide the thing you're centering on, is? Walter
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor