liveBook · Manning

Method

As explained in Learn AI-Assisted Python Programming, Second Edition

A method is a function associated with an object or type and invoked through that association.

A method is a function associated with a particular type. Call it by placing the value first, followed by a dot, then parentheses containing any arguments. section 4.3.4

Cleaning a phone number

The replace() method removes selected characters from a string: phone_number.replace('(', '') replaces each opening parenthesis with nothing. Applying it again removes closing parentheses and hyphens. Copilot’s Explain feature can clarify unfamiliar methods. section 4.3.4

>>> 'abc'.isupper()      #1
False                   
>>> 'Abc'.isupper()     
False                   
>>> 'ABC'.isupper()     
True                    
>>> 'abc'.isdigit()        #2
False                      #2
>>> '345bc'.isdigit()      #2
False                      #2
>>> '345'.isdigit()        #2
True                       #2

>>> 'abc6'.isalnum()         #3
True                         #3
>>> 'abc def'.isalnum()      #3
False                        #3
>>> 'abcdef#'.isalnum()      #3
False                        #3

Try string methods that test capitalization, digits, and alphanumeric content, then compare their Boolean results. section 4.3.4

Common method roles include:

  • Converting strings between lowercase and uppercase. section 4.3.4
  • Searching, formatting, or replacing parts of strings. section 4.3.4

How Learn AI-Assisted Python Programming, Second Edition covers it

How deep it goes
Defines method syntax and demonstrates string operations, but stops short of implementation internals.
Examples
Demonstrates replace(), isupper(), isdigit(), and isalnum() through phone-number cleaning and interactive string tests.
What it assumes
Teaches method basics alongside assumed familiarity with values, functions, variables, and strings.
What you can do after
Evaluate unfamiliar methods, call string methods, and request explanations with Copilot’s Explain feature.
How it connects
Connects methods with functions, types, strings, lists, and immutable values.

Also explained in

Compare how 20 books explain method →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn AI-Assisted Python Programming, Second Edition. The section links point to the parts of the book it draws on.