Hello,
I am new to Python and programming and i find it difficult to search for specific topics.
For example i was searching for string methods and i get a lot of results but not the one i am looking for.
I managed to find the link trough google String Methods but i don’t understand why it doesn’t show up in the documentation search results?
Is there a specific way to search for what you are looking?
I also tried “String Methods” with the quotation marks and all other variations.
The quickest was to search for string() and from string page there is a link to String Methods.
Is it not possible to get the String Methods heading found with search?
Thanks.
Searching the docs does require a little experience with what terms to use.
Since string functions means methods on a str object you can search for str.
But you have to notice that str is about the 20th result!
Once you get to the str page the it has the information you are after.
It would help if the search put exact matches at the start of the results, but it does not.
Sometimes using the help function from the REPL is faster.
>>> help(str)
Thank you. I will try to use the REPL more so i can get used to it.
cameron
(Cameron Simpson)
July 16, 2023, 4:27am
4
I also often go first to the index rather than the search field. For example, in the “S” section:
https://docs.python.org/3/genindex-S.html
There’s this under the word “string”:
string
__format__() (object method)
__str__() (object method)
conversion, [1]
format() (built-in function)
formatted literal
formatting, printf
immutable sequences
interpolated literal
interpolation, printf
item
methods
module, [1]
object, [1], [2]
object representation
PyObject_Str (C function)
str (built-in class)
str() (built-in function)
text sequence type
and the word “methods” does in fact point to the string methods section
you found.
Cheers,
Cameron Simpson cs@cskk.id.au
One way to have quick access to methods is using interactive interpreter:
>>> str. # press two times TAB
str.capitalize( str.expandtabs( str.isalpha( str.isnumeric( str.ljust( str.removeprefix( str.rpartition( str.strip(
str.casefold( str.find( str.isascii( str.isprintable( str.lower( str.removesuffix( str.rsplit( str.swapcase(
str.center( str.format( str.isdecimal( str.isspace( str.lstrip( str.replace( str.rstrip( str.title(
str.count( str.format_map( str.isdigit( str.istitle( str.maketrans( str.rfind( str.split( str.translate(
str.encode( str.index( str.isidentifier( str.isupper( str.mro() str.rindex( str.splitlines( str.upper(
str.endswith( str.isalnum( str.islower( str.join( str.partition( str.rjust( str.startswith( str.zfill(
>>> list.
list.append( list.clear( list.copy( list.count( list.extend( list.index( list.insert( list.mro() list.pop( list.remove( list.reverse( list.sort(
Method names usually give pretty good idea what they do. One can always have more specific information by using help. What does .zfill method do?
>>> help(str.zfill)
Help on method_descriptor:
zfill(self, width, /)
Pad a numeric string with zeros on the left, to fill a field of the given width.
The string is never truncated.