Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Python Naming Rules for Variables | Variables and Types in Python
Introduction to Python(ihor)

bookPython Naming Rules for Variables

Variables should always have descriptive names for better readability and maintainability. However, concise names like x, y, or temp are acceptable when the context is clear and unambiguous.

The preferred way to name variables in Python is to use snake_case, where words are written in lowercase and separated by underscores.

12
# Snake_case is preferred in Python because it improves readability each_word_in_lowercase_and_separated_with_underscores = 1000
copy

Regardless of the naming style, variable names must always follow established naming rules and conventions.

Python will raise an error if variable names violate naming rules, such as starting with a number, using spaces, special characters, reserved keywords, or invalid characters.

question mark

Which of these would be valid variable names in Python?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 2

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

Ask me questions about this topic

Summarize this chapter

Show real-world examples

Awesome!

Completion rate improved to 1.67

bookPython Naming Rules for Variables

Swipe to show menu

Variables should always have descriptive names for better readability and maintainability. However, concise names like x, y, or temp are acceptable when the context is clear and unambiguous.

The preferred way to name variables in Python is to use snake_case, where words are written in lowercase and separated by underscores.

12
# Snake_case is preferred in Python because it improves readability each_word_in_lowercase_and_separated_with_underscores = 1000
copy

Regardless of the naming style, variable names must always follow established naming rules and conventions.

Python will raise an error if variable names violate naming rules, such as starting with a number, using spaces, special characters, reserved keywords, or invalid characters.

question mark

Which of these would be valid variable names in Python?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 2
some-alt