Hero Background

Next-Gen App & Browser Testing Cloud

Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

Next-Gen App & Browser Testing Cloud

What does period mean in Python?

A period, or dot, in Python is the attribute-access operator. It tells Python that you want to reach the data or behavior that belongs to a specific object, module, or package. When you write something like text.upper(), the dot signals Python to look up the upper method on the string object named text and run it. The same operator also accesses module contents and, inside import statements, indicates relative package paths.

Understanding the Dot Operator in Python

In Python everything is an object, and objects bundle together attributes (their data) and methods (their behavior). The dot is how you get to those members. Formally, an attribute reference is a primary followed by a period and a name; the object to the left of the dot is asked to produce the attribute whose name follows it.

name = "lambdatest"

# Method call: run upper() on the string object
print(name.upper())      # LAMBDATEST

# Attribute access on an object
class User:
    def __init__(self, email):
        self.email = email   # 'email' is an attribute

u = User("[email protected]")
print(u.email)           # [email protected]

Accessing Module and Package Members

The dot also reaches names defined inside an imported module. After importing a module, type the module name, a dot, and the function, class, or constant you want to use.

import math

print(math.pi)           # 3.141592653589793
print(math.sqrt(16))     # 4.0

# Dotted paths can go several levels deep
import os.path
print(os.path.join("dir", "file.txt"))

The Dot in Import Statements (Relative Imports)

Inside an import statement the dot has a different job: it describes a location relative to the current package. A single dot means the current package, two dots mean the parent package, and three dots mean the grandparent, and so on up the hierarchy.

# Import 'utils' from the current package
from . import utils

# Import a name from a sibling module in the current package
from .helpers import login

# Import from the parent package
from .. import config

Dot vs Decimal Point and Method Chaining

Not every period is the attribute operator. In a numeric literal such as 3.14, the period is a decimal point that creates a floating-point number. When several dots appear in one expression, they form a method chain, where each call acts on the object returned by the previous one, which is the recommended way to keep transformations readable.

# Decimal point: this dot builds a float
price = 3.14
print(type(price))       # <class 'float'>

# Method chaining: each dot works on the previous result
slug = "  Hello World  ".strip().lower().replace(" ", "-")
print(slug)              # hello-world

Common Mistakes and Troubleshooting

  • AttributeError: The object left of the dot lacks that member, often a typo or the wrong type. Check the value with type(obj).
  • Calling a method on None: If a function returns None and you chain a dot onto it, you get an error. Verify the return value first.
  • Forgetting parentheses: text.upper references the method object; text.upper() actually calls it.
  • Relative import errors: Dotted relative imports only work inside a package run as a module, not when a file is run directly as a script.
  • Confusing decimal and dot: Remember 2.0 is a float literal, while obj.attr is attribute access; the period means different things by context.

Conclusion

The period in Python is small but versatile. Most often it is the attribute-access operator that reaches an object's data and methods and the names inside modules. In import statements it signals relative package paths, and inside a numeric literal it is simply a decimal point. Knowing which role the dot is playing in a given line makes reading and debugging Python, especially test scripts, far easier.

Frequently Asked Questions

What does a period (dot) mean in Python?

A period, or dot, in Python is the attribute-access operator. It lets you reach the data (attributes) and behavior (methods) that belong to an object, module, or package. For example, text.upper() calls the upper method on the string object text.

What is dot notation used for in Python?

Dot notation is used to access attributes and methods of objects, reach names inside imported modules (like math.pi), chain calls together, and, in import statements, indicate relative package paths such as from . import module.

What does a dot mean in a Python import statement?

In an import, a dot signals a relative import. A single dot means the current package, two dots mean the parent package, and three dots mean the grandparent. For example, from . import utils imports utils from the current package.

Is the period in 3.14 the same as dot notation?

No. The period in a number like 3.14 is a decimal point that marks a floating-point literal. Dot notation, by contrast, is the operator that accesses attributes or methods, such as name.strip(). They look alike but serve entirely different roles.

What is method chaining with dots in Python?

Method chaining uses several dots in one expression to call methods in sequence on the returned object, such as text.strip().lower().replace(' ', '-'). Each dot acts on the result of the previous call, letting you transform data in a single readable line.

Why do I get an AttributeError when using a dot?

An AttributeError means the object to the left of the dot does not have the attribute or method you named. It is usually caused by a typo, calling a method on None, or using the wrong object type. Print the object and its type to debug.

Related Questions

Test Your Website on 3000+ Browsers

Get 100 minutes of automation test minutes FREE!!

Test Now...

KaneAI - Testing Assistant

World’s first AI-Native E2E testing agent.

...

TestMu AI forEnterprise

Get access to solutions built on Enterprise
grade security, privacy, & compliance

  • Advanced access controls
  • Advanced data retention rules
  • Advanced Local Testing
  • Premium Support options
  • Early access to beta features
  • Private Slack Channel
  • Unlimited Manual Accessibility DevTools Tests