Variables
A variable is a name that refers to a value, so you store something once and use it anywhere after that line.
Last updated: 30 Sep, 2026 · Python 3.14
In print() the ticket text was typed inside every print. A variable stores it once under a name.
print(). In a .py file and in the editor here, wrap it in print(), as the run below does. The video also calls int and float reserved keywords; they are built-in type names, and True and False are the keywords.print(type(1))
print(type(10.0))
print(type("Hello"))
print(type(True))
a = 10
print(type(a))
a = 'Krish Naik'
print(type(a))<class 'int'> <class 'float'> <class 'str'> <class 'bool'> <class 'int'> <class 'str'>
print(type(1)) shows <class 'int'> where the notebook showed int: the same type, printed in full. The same a held an int and then a string, because a Python variable takes the type of whatever it holds. The rest of this page does the same with a support ticket.
Syntax:
name = valueStoring a ticket in a variable
ticket = "My parcel has not arrived"
print(ticket)My parcel has not arrived
= means store, not equals. The line says: put this text somewhere and call it ticket. After that, writing ticket gives you the text back.
Changing a variable
waiting = 3
print("Waiting:", waiting)
waiting = waiting + 1
print("Waiting:", waiting)Waiting: 3 Waiting: 4
print accepts several values separated by commas and puts a space between them.
waiting = waiting + 1 looks odd as maths but reads fine as instructions. Python works out the right side first, 3 + 1, then stores the result under the name on the left.
Checking a value's type
Every value has a type, which decides what you can do with it. type tells you which one you have.
print(type("My parcel has not arrived"))
print(type(3))
print(type(4.5))
print(type(True))<class 'str'> <class 'int'> <class 'float'> <class 'bool'>
str is text, short for string. int is a whole number. float is a number with a decimal point. bool is either True or False.
Using a name that does not exist
ticket = "My parcel has not arrived"
print(tickt)Traceback (most recent call last):
File "main.py", line 2, in <module>
print(tickt)
NameError: name 'tickt' is not defined. Did you mean: 'ticket'?A typo in a name is a NameError. Python only knows the names you have stored something under, and here it even suggests the one you probably meant.
Good names vs bad names
| Name | Allowed | Reads well |
|---|---|---|
ticket_count | Yes | Yes, says what it holds |
x | Yes | No, says nothing |
2tickets | No, starts with a digit | - |
ticket-count | No, - is minus | - |
Where variables show up in AI code
- Holding the text of a prompt before it is sent to a model.
- Keeping settings such as the model name in one place, so changing it is one line.
ticket above the line ticket = ... is a NameError.Related
- Previous: print()
- Next: Strings
- Reference: An Informal Introduction to Python
- Store your name in a variable called
customerand print it. - Add a line
waiting = waiting - 2and print the result. - Print
type("3"). The quotes decide the type, not what is inside them.
Slow is fine. Stopping is the only problem.