Home >Backend Development >Python Tutorial >How to define a variable in python
How to define a variable in Python?
In python, each variable must be assigned a value before use. The variable will not be created until the variable is assigned a value
The equal sign (=) is used to assign a value to the variable
=The left side is a variable name
=The right side is the value stored in the variable
Variable name = value
After the variable is defined, it can be used directly later
Example:
#!/usr/bin/python # -*- coding: UTF-8 -*- counter = 100 # 赋值整型变量 miles = 1000.0 # 浮点型 name = "John" # 字符串 print counter print miles print name
Output:
100 1000.0 John
Related recommendations: "Python Tutorial"
The above is the detailed content of How to define a variable in python. For more information, please follow other related articles on the PHP Chinese website!