Theory of Intelligence
11TH•Computer Science•Python Programming•Question 4

Solution

Explain the concept of variables in Python.

Solution

A variable is a storage container in a computer's memory, that allows storage, retrieval and manipulation of data. The value of a variable can change throughout the execution of a program:

PYTHON
age = 71
print("Ahmad lived for", age, "years")
age = 60
print("Iqbal lived for", age, "years")

Variable names in Python must begin with a letter or an underscore. Later characters can be letters, digits, or underscores. Names are case-sensitive, and reserved keywords such as for, while, and if cannot be used as variable names.

Common types include:

  • Integer (int): whole numbers, for example age = 17
  • Floating-point (float): decimal numbers, for example price = 19.99
  • String (str): text, for example name = "Ali"
  • Boolean (bool): True or False, for example is_student = True

Discuss theoretical concepts, mathematical formulas, and architectural foundations.

Supports inline code with `backticks`
No comments yet. Be the first to start the discussion!