December 2017
Beginner
412 pages
10h 8m
English
Because every method in class str requires a string as the first argument (and, more generally, because every method in any class requires an object of that class as the first argument), Python provides a shorthand form for calling a method where the object appears first and then the method call:
| | >>> 'browning'.capitalize() |
| | 'Browning' |
| | >>> 'Sonnet 43'.center(26) |
| | ' Sonnet 43 ' |
| | >>> 'How do I love thee? Let me count the ways.'.count('the') |
| | 2 |
When Python encounters one of these method calls, it translates it to the more long-winded form. We will use this shorthand form throughout the rest of the book.
The help documentation for methods uses this form. Here is the help for ...
Read now
Unlock full access