liveBook · Manning

Dotted notation

As explained in Get Programming: Learn to code with Python

Dot notation is Python syntax that accesses an operation or attribute through an object by placing a dot between the object and the member name.

Dotted notation accesses an operation or property through an object: write the object, a dot, and the member name. For example, a.lower() changes the letters in string a to lowercase. Python uses this form for operations designed for a specific object type, such as strings. section 7.3 section 30.3

Read the expression from left to right:

  • In "wow".replace("o", "a"), replace operates on a string. section 30.3
  • In [1, 2, 3].append(4), append operates on a list. section 30.3
  • In {1: 1, 2: 2}.keys(), keys operates on a dictionary. section 30.3
  • len("lalala") uses a general function instead: the object goes inside the parentheses. section 7.3 section 30.3

Calling through an object

essay = "Ups AND Downs" print(essay.lower()) print(essay.upper()) Here, essay is the object. The dot selects a string operation, and the parentheses call it. Case conversion changes letters while leaving numbers and special characters unchanged. section 7.3

c = Circle()
Circle.change_radius(c, 2)
r = Circle.get_radius(c)
print(r)

Compare ordinary object calls with explicit calls through the class name. c.change_radius(2) supplies c as self automatically; Circle.change_radius(c, 2) supplies it explicitly. section 31.6

How Get Programming: Learn to code with Python covers it

How deep it goes
Explains object properties, operations, type inference, and explicit class calls, while deferring deeper object-oriented implementation details.
Examples
Uses lower(), upper(), replace(), append(), keys(), and Circle radius methods as concrete examples.
What it assumes
Assumes familiarity with basic Python objects and functions while building understanding of object properties and behaviors.
What you can do after
Apply it in Python to call operations on strings, lists, dictionaries, and custom objects.
How it connects
Connects objects, object types, properties, behaviors, methods, classes, strings, lists, and dictionaries.

Also explained in

Compare how 9 books explain dotted notation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Get Programming: Learn to code with Python. The section links point to the parts of the book it draws on.