Home > Backend Development > Python Tutorial > How to define variables in python

How to define variables in python

王林
Release: 2024-03-01 19:25:02
forward
627 people have browsed it

How to define variables in python

In python, variables can be defined by assignment. You can use the equal sign (=) to assign a value to a variable. The naming of variables follows some rules:

  • Variable names can only contain letters, numbers and underscores.
  • Variable names cannot start with numbers.
  • Variable names are case-sensitive. For example, name and Name are different variable names.
  • The variable name cannot be a keyword of Python, such as if, for, etc.

The following are some examples of defining variables:

name = "John"# 字符串类型的变量
age = 25# 整数类型的变量
height = 1.75# 浮点数类型的变量
is_student = True# 布尔类型的变量
Copy after login

You can change the value of the variable at any time as needed, for example:

name = "Alice"
age = 30
Copy after login

In this way, the value of variable name becomes "Alice", and the value of variable age becomes 30.

The above is the detailed content of How to define variables in python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:lsjlt.com
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