[파이썬] 변수 네이밍 스타일

When writing code, one of the most important considerations is choosing appropriate variable names. Variable naming style refers to the conventions and patterns followed when naming variables in a programming language. Python, like many other programming languages, has several commonly used variable naming styles. Let’s explore some of them:

1. Camel Case

In camel case, the first letter of each word is capitalized except for the first word. This style is often preferred in Python for Class names.

class UserDetails:
    userName = "John"
    userAge = 25

2. Pascal Case

In pascal case, also known as capitalized words or upper camel case, the first letter of each word is capitalized, including the first word. This style is commonly used for function names and class methods in Python.

def CalculateSum(a, b):
    return a + b

3. Snake Case

In snake case, all letters are in lowercase and words are separated by underscores. This style is widely used in Python for variable names, module names, and function names.

user_name = "John"
user_age = 25

def calculate_sum(a, b):
    return a + b

4. Upper Case

In upper case, all letters are in uppercase and words are separated by underscores. This style is used for constants in Python.

PI_VALUE = 3.14159
MAX_VALUE = 100

5. Hungarian Notation

Hungarian notation prefixes a token to indicate the type or purpose of the variable. Although less common in Python, it is still sometimes used.

str_name = "John"
int_age = 25

Remember, consistency is key when following variable naming styles. It is essential to choose a style that aligns with Python’s naming conventions and the guidelines of the project or organization you are working with. By adopting a consistent naming style, your code will become more readable and maintainable for yourself and others.

So, next time you write code in Python, make sure to choose an appropriate variable naming style to keep your code clean and understandable. Happy coding!