[Tutor] Python Docs (Was: Reformatting phone number)

Dotan Cohen dotancohen at gmail.com
Thu Aug 21 21:27:06 CEST 2008


2008/8/21 Alan Gauld <alan.gauld at btinternet.com>:
> "Dotan Cohen" <dotancohen at gmail.com> wrote
>
>> Let's start from there. I need the startswith() function, but I do not
>> know it's name. I search for "strings" and find this:
>> 4. String Services
>>   * 4.1 string -- Common string operations
>>         o 4.1.3 String functions
>
> Personally I rarely start with the documentation.
> I'd start either with the >>> prompt and the help()
> function or I may use dir() as in dir("") to get a list
> of all the attributes - including methods - of an object.
> If I don't undertand what dir/help tell me, or don't see
> anything promising,  then I will search the docs.
>
> So here is my session looking for startwith...
>
>>>> help("")
>
>>>> dir("")
>
> ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__',
> '__
> ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__',
> '__g
> t__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__',
> '__mul__
> ', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
> '__rmod__', '
> __rmul__', '__setattr__', '__str__', 'capitalize', 'center', 'count',
> 'decode',
> 'encode', 'endswith', 'expandtabs', 'find', 'index', 'isalnum', 'isalpha',
> 'isdi
> git', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower',
> 'lst
> rip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition',
> 'rsplit'
> , 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase',
> 'title', '
> translate', 'upper', 'zfill']
>>>>
>>>> help("".startswith)
>
> Help on built-in function startswith:
>
> startswith(...)
>   S.startswith(prefix[, start[, end]]) -> bool
>
>   Return True if S starts with the specified prefix, False otherwise.
>   With optional start, test S beginning at that position.
>   With optional end, stop comparing S at that position.
>   prefix can also be a tuple of strings to try.
>
>
> If I'd done help(str) instead of help("") in the first case
> I'd have got the full help screen for string objects including
> startswith..
>
> Never forget the >>> prompt as a source of research.

Oh, I have a lot to learn! Thanks, you have no idea how many different
angles have become clear to me because of this post.

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il
א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת

ä-ö-ü-ß-Ä-Ö-Ü


More information about the Tutor mailing list