Can python assign values ​​continuously?

anonymity
Release: 2019-06-15 14:10:15
Original
5867 people have browsed it

If continuous assignment in python depends on the order, you should pay attention to the order of continuous assignment in python

For example, expression: a=b=1

Proceed a=1 first

Then b=1

Can python assign values ​​continuously?

Code:

class Node():
def __init__(self,elem,nextnode=None):
self._elem=elem
self._nextnode=nextnode
a=Node('a')
a=a._nextnode=Node('b')
Copy after login

According to understanding: python should first perform a._nextnode=Node(' b'), and then a=Node('b')

But in fact, python first performs a=Node('b'), and then a._nextnode=Node('b')

>>> a is a._nextnode
True
Copy after login

So the correct order is a._nextnode=a=Node('b')

The above is the detailed content of Can python assign values ​​continuously?. 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