Skip to content

Variables & Data Types

  • ✨ Python variables spring into existence when you assign them. and can change type at runtime. ✅
  • 🔁 Python variables are created when you are first assigned a value — they reference objects and Python is dynamically typed, so a name can refer to different types over time. ♻️
  • 🧭 Use clear, descriptive names (snake_case by convention), do not start identifiers with digits, and avoid reserved keywords. 🚫
  • 🔍 Use type(value) to inspect a value’s type.
  • You can assign multiple variables in one line (e.g., x, y = 1, 2). By convention, constants are written in ALL_CAPS. 📣
quantity = 12 # int
unit_price = 50.00 # float
fruit = "Apple" # string
in_stock = True # bool

Screenshot of Python code showing variable assignments and printing their types.

Screenshot of Python code showing variable assignments and printing aaaatheir types

Complete Code :

quantity = 12 # int
unit_price = 50.00 # float
fruit = "Apple" # string
in_stock = True # bool
print(type(quantity)) # <class 'int'>
print(type(unit_price)) # <class 'float'>
print(type(fruit)) # <class 'str'>
print(type(in_stock)) # <class 'bool'>

📌 Let’s compare it with other programming languages.

In C# and JavaScript you must declare a type or use let/const:


C# Example:
int count = 1;
string name = "Banky";

JavaScript Example:
let count = 1;
const name = "Banky";
👉 Click to expand: Comparison of common naming conventions

Using the example: “maximum retry count”

ConventionExampleTypical Usage
snake_casemax_retry_countVariables, functions (Python, Ruby)
camelCasemaxRetryCountVariables, methods (JS, C#, Java)
PascalCaseMaxRetryCountClasses, enums, types
ALL_CAPSMAX_RETRY_COUNTConstants, environment variables

🔑 Key takeaway:
Naming conventions are not cosmetic — they communicate intent to other developers.


  1. How do you create a string in Python?

    Correct: name = “Ada”
  2. Which of these is a valid Python variable name?

    Correct: total_cost
  3. What built-in function shows a variable’s type?

    Correct: type()
  4. What happens when you reassign x = 1 to x = “one” in Python?

    Correct: x now references a string
  5. How do you assign multiple variables in one line?

    Correct: x, y = 1, 2
  6. By convention, how do you name constants in Python?

    Correct: ALL_CAPS
  7. What’s the Pythonic way to swap two variables?

    Correct: a, b = b, a
  8. Which assignment would raise a SyntaxError?

    Correct: 1value = 5
  9. Which is the correct boolean literal in Python?

    Correct: True
  10. How do you create a multiline string?

    Correct: Using triple quotes