Home >Backend Development >Python Tutorial >How to define a variable in python

How to define a variable in python

藏色散人
藏色散人Original
2019-07-06 11:04:3113151browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn