What is a convention to name a protected method in Python?

Experience Level: Junior
Tags: Python

Answer

The protected methods should be prefixed with single underscore.

Example:

def _add(x: int, y: int) -> int:
    return x + y;

Python for beginners
Python for beginners

Are you learning Python ? Try our test we designed to help you progress faster.

Test yourself