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

How to define a variable in python

藏色散人
Release: 2019-07-06 11:04:31
Original
13119 people have browsed it

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
Copy after login

Output:

100
1000.0
John
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template