Python for AIPython 3.10+ · Pydantic 2.12
Dashboard
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
34 small wins to finish your pathNext lesson →

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.

type() and variable assignment · from Tutorial 1- Anaconda Installation and Python Basics · 10:46 to 13:12
The video runs each line in a Jupyter notebook, which shows the value of a cell's last line without 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.
ExampleFrom the video, run here
print(type(1))
print(type(10.0))
print(type("Hello"))
print(type(True))

a = 10
print(type(a))
a = 'Krish Naik'
print(type(a))

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:

python
name = value

Storing a ticket in a variable

Example
ticket = "My parcel has not arrived"
print(ticket)

= 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

Example
waiting = 3
print("Waiting:", waiting)

waiting = waiting + 1
print("Waiting:", waiting)

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.

Example
print(type("My parcel has not arrived"))
print(type(3))
print(type(4.5))
print(type(True))

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

Example
ticket = "My parcel has not arrived"
print(tickt)

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

NameAllowedReads well
ticket_countYesYes, says what it holds
xYesNo, says nothing
2ticketsNo, starts with a digit-
ticket-countNo, - 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.
Watch out. A variable must be stored before the line that uses it. Python runs from the top, so using ticket above the line ticket = ... is a NameError.
Try it yourself
  • Store your name in a variable called customer and print it.
  • Add a line waiting = waiting - 2 and print the result.
  • Print type("3"). The quotes decide the type, not what is inside them.
Previousprint()

Slow is fine. Stopping is the only problem.