A variable is a name for a piece of information, like a labelled box. You create one with =, which means "store this value under that name".
name = "Sita"
age = 16
print(name)
print(age)
Output:
Sita
16
The four basic types
| Type | Python name | Example | Used for |
|---|---|---|---|
| Whole number | int | 25, -3 | counting, ages, marks |
| Decimal number | float | 3.14, 72.5 | prices, measurements |
| Text | str | "Kathmandu" | names, messages |
| True or False | bool | True, False | yes/no decisions |
Use type() to ask Python what kind of value something is:
print(type(25))
print(type(72.5))
print(type("Pokhara"))
print(type(True))
Output:
<class 'int'>
<class 'float'>
<class 'str'>
<class 'bool'>
Naming variables
- Use letters, digits and underscores, and do not start with a digit.
- Names are case sensitive:
marksandMarksare different. - Choose meaningful names:
total_marksis better thanx.
Joining text with f-strings
To put variables inside a sentence, start the text with f and put the variable in curly brackets.
name = "Ram"
marks = 78.5
print(f"{name} scored {marks} marks")
Output:
Ram scored 78.5 marks
Getting input from the user
input() asks the user to type something. It always gives you text, so convert it with int() or float() if you need a number. This example waits for a keyboard, so try it on your own computer:
name = input("What is your name? ")
age = int(input("How old are you? "))
print(f"Hello {name}, next year you will be {age + 1}")
Try it yourself
- Make variables for your name, your age and your favourite subject, then print one sentence using an f-string.
- Print the type of each variable.
- Ask the user for two numbers and print them side by side.
Next lesson: doing arithmetic and comparing values with operators.

Comments
Loading comments…