본문 바로가기
Python(Eng. ver)

2. Variables in Python

by 곽정우 2024. 3. 13.

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.

'Python(Eng. ver)' 카테고리의 다른 글

6. Python collection type - Set  (0) 2024.03.14
5. Python collection type - Tuple  (0) 2024.03.14
4. Python collection type - List  (0) 2024.03.14
3. Python String & why 0.1+ 1.1 ≠ 1.2  (0) 2024.03.13
1. Python Output  (0) 2024.03.12