Python(Eng. ver)
2. Variables in Python
곽정우
2024. 3. 13. 16:24
1. Variable
Variables are an important concept used to store and manage data in programming. A variable is a named memory space that is used to store or reference a value.
2. Data Types of Variables
- Dynamic typing: Automatically infer the type of a variable when assigning a value without having to declare it.
- Pros: Reduces the burden on programmers and can make code more concise.
- Cons: Values of the wrong type can be assigned to variables.
Basic Data Types:
- Integer Type (int): Represents integer values (e.g., 1, 2, 3)
- Floating-Point Type (float): Represents real numbers (e.g., 3.14, 1.234)
- String Type (str): Represents characters or strings (e.g., "Hello", "Python")
- Boolean Type (bool): Represents True or False values
Collection Data Types:
- List (list): A data structure that stores multiple values sequentially (e.g., [1, 2, 3], ["apple", "banana"])
- Tuple (tuple): Similar to a list but is immutable (e.g., (1, 2, 3), ("Kim Apple", 20))
- Dictionary (dict): A data structure that stores key-value pairs (e.g., {"name": "Kim Apple", "age": 20})
- Set (set): A data structure that stores unique values (e.g., {1, 2, 3})
3. Variable Deletion
del statement :
- It is used to delete variables.
- It removes the specified variable and releases the corresponding memory space.
- Once a variable is deleted, you can no longer access it using that name.
4. Additional Information
- Variable Naming Rules:
- Must start with a letter, number, or underscore (_).
- Cannot contain special characters.
- Case-sensitive.
- Cannot use reserved keywords.
- Variable Declaration:
- Variable declaration happens automatically when you assign a value to it.