Python BasicsCore· 35 min read

Variables & Data Types

Store information in variables — no special keyword needed.

What you will learn

  • Create variables
  • Use the main data types
  • Check a type with type()

Just name it

A variable is a labelled box that holds a value so you can use it again later. In Python you create one simply by giving it a name, an = sign, and a value — no let or var needed.

Variables in Python
name = "Asha"
age = 22
height = 5.4
is_student = True

print(name, "is", age, "years old")

Each line stores a value in a name: name holds the text "Asha", age holds the whole number 22, height holds the decimal 5.4, and is_student holds True (a yes/no value). The = means “put this value into this box.” The last line reads three of those boxes back out and prints them as one sentence — notice the words "is" and "years old" are in quotes (printed exactly) while name and age are not (their stored values are used).

Note: Output: Asha is 22 years old

The main types

Every value in Python has a type — what kind of thing it is. Knowing the type matters because it decides what you can do with a value (you can add numbers, but not subtract text). Here are the six you will meet most:

TypeExampleMeaning
str"hello"Text (string)
int42Whole number
float3.14Decimal number
boolTrue / FalseYes / no
list[1, 2, 3]A list of items
dict{"a": 1}Key–value pairs

If you are ever unsure what kind of value you have, the built-in type() function will tell you. You pass it a value and it reports the type:

type() tells you the data type
print(type("hi"))   # <class 'str'>
print(type(42))     # <class 'int'>

The first line asks the type of "hi" — because it is in quotes it is text, so Python answers str (string). The second asks the type of 42, a whole number, so Python answers int (integer). The <class '...'> wrapper is just Python’s way of naming a type.

Note: Output: <class 'str'> <class 'int'>

Tip: Use clear, lowercase names with underscores: first_name, total_price (this is the Python style, called snake_case).

Q. How do you create a variable in Python?

Answer: Python needs no keyword — just write name = value, e.g. x = 5.

✍️ Practice

  1. Create variables for your name, age and city, then print a sentence.
  2. Print the type() of three different values.

🏠 Homework

  1. Make variables of all six types and print each.
Want to learn this with a mentor?

CodingClave runs guided, project-based training (28-day, 45-day & 6-month batches).

Explore Training →