Python中关键字is与==的区别简述

WBOY
Release: 2016-06-16 08:43:00
Original
1364 people have browsed it

本文以简单示例分析了python中关键字is与 ==的区别,供大家参考一下。

首先说明一下Python学习中几个相关的小知识点。

Python中的对象包含三要素:id、type、value
其中:id用来唯一标识一个对象type标识对象的类型value是对象的值

is判断的是a对象是否就是b对象,是通过id来判断的

==判断的是a对象的值是否和b对象的值相等,是通过value来判断的

具体示例如下:

>>> a=100
>>> b=100.0
>>> a is b
False
>>> a==b
True
>>> id(a)
30696848L
>>> id(b)
48685000L
>>> id(a)==id(b)
False
Copy after login
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!