Python Variable Naming Conventions

Let's now talk about Variables in Python. What is a variable? Think of it like a box, you give it a name and store a value inside it. Example: a = 10 name = 'Alice' price = 19.99 Here, a, name, price are all variables in which we have stored some value or data. Simple right? But here's where most beginners make mistakes- naming their variables wrong. There are 3 conventions you need to follow: 1️⃣ First letter should be lowercase (best practice as per PEP8) 2️⃣ Never start a variable name with a number 3️⃣ Never use spaces, use an underscore instead Break any of these and Python will throw an error before your code even runs. Get these right from day one and you'll save yourself a lot of frustration later. #Python #DataAnalytics #data #python #learnpython #dataanalyst #pythonforbeginners

  • graphical user interface, text, application, email

> First letter must always be lowercase Patently false. Per the [Python language reference](https://docs.python.org/3/reference/lexical_analysis.html#names-identifiers-and-keywords): > Names are composed of uppercase and lowercase letters (A-Z and a-z), the underscore (_), digits (0 through 9, which cannot appear as the first character, and non-ASCII characters. According to [PEP8](https://peps.python.org/pep-0008/#prescriptive-naming-conventions):  - Modules should have short, all-lowercase names.  - Class names should normally use the CapWords convention.   - Function [and variable] names should be lowercase, with words separated by underscores as necessary to improve readability.

To view or add a comment, sign in

Explore content categories