Python learning basics - a detailed introduction to variables and assignments

高洛峰
Release: 2017-03-21 13:58:01
Original
1577 people have browsed it

Variables: The program will use a lot of temporary storage data when it is running. At this time, variables and the names of temporary data are used.

#Variables in Python do not need to be declared and can be used directly. The data type of the variable is determined by assignment.

>>> name="like"
>>> name
'like'
>>> age = 35
>>> name,age
('like', 35)
Copy after login

Use the type command to view the type of the variable:

>>> type(name)
<class &#39;str&#39;>
>>> type(age)
<class &#39;int&#39;>
>>> print(name,age)
like 19
Copy after login

The variable stores not the assigned data, but the address where the data is located ( The address is not the address of the memory), the id can check the address of the variable

>>> a = 3
>>> b = a
>>> id(a),id(b)
(1661927952, 1661927952)
>>> a = 5
>>> id(a),id(b)
(1661928016, 1661927952)
Copy after login

Variable naming rules

1. Explicit, easy to understand .

2. Variable name can only be a combination of letters, underscores, and numbers. Numbers cannot begin, and cannot contain -!@#$%^&*() and other special symbols.

For example: nums_of_alex_gf = 19

            NumsOfAlexGf = 19

The above is the detailed content of Python learning basics - a detailed introduction to variables and assignments. 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