directory

  • A preface.
  • The Python operator ==
  • The Python operator is
  • Four. Guess you like it

Recommended path for learning Python: Python Learning Directory >> Python Basics

In Python, the is and == operators are used to check whether two variables are equal and return True or False.

A preface.

** Built-in function id** is used to obtain the memory address of a variable. You can think of the memory address as a string of numbers, just like everyone has an ID number!

#! Usr /bin/env python # -* -coding :utf-8 _*- "" www.codersrc.com @file :Python is different from ==. Py @time :2021/3/25 23:00 @Motto: No accumulation of small steps to a thousand miles, no accumulation of small streams into rivers and oceans, the wonderful life of the program needs unremitting accumulation! """ a = 5 b = False c = "hello" print("a memory address: {}". Format (id(a)) print("b memory address: {}". Format (id(b))) print("b memory address: {}". {}". Format (id(c))) "output: a Memory address: 1784504608 b Memory address: 1784012992 c Memory address: 2126520897696"Copy the code

The Python operator ==

If the values of the two variables are equal, then the operator == is True and returns True; Otherwise return False; Example code is as follows:

#! Usr /bin/env python # -* -coding :utf-8 _*- "" www.codersrc.com @file :Python is different from ==. Py @time :2021/3/25 23:00 @Motto: No accumulation of small steps to a thousand miles, no accumulation of small streams into rivers and oceans, the wonderful life of the program needs unremitting accumulation! Print (a==b) print(a==b) print(a==b) print(a==b) print(a==b) print(a==b) B = "HELLO WORLD" c = "HELLO "d = "HELLO WORLD" print(a==b,a==c,b==c,a==d)  True True False False False False True '''Copy the code

The Python operator is

  • 1. The values of the two variables are equal.
  • 2. The address of the variable is the same (the memory address of the variable can be obtained through the built-in function ID).

Operator is True if both conditions are met and returns True. Otherwise, failure to satisfy any of these conditions returns False; Example code is as follows:

#! Usr /bin/env python # -* -coding :utf-8 _*- "" www.codersrc.com @file :Python is different from ==. Py @time :2021/3/25 23:00 @Motto: No accumulation of small steps to a thousand miles, no accumulation of small streams into rivers and oceans, the wonderful life of the program needs unremitting accumulation! "" a = 333333 b = 333333.0 print(id(a)) print(id(b)) print(a is b) print("***"*20) a = 3 b = 3 print(id(a)) print(id(b)) print(a is b) print("***"*20) a = "hello world" b = "HELLO WORLD" c = "hello " d = "hello world" Print (id(a)) print(ID (b)) print(ID (c)) print(id(d)) print(id(d)) print(a is b,a is C,b is C,a is D)  2039213240016 2039234381168 False ************************************************************ 1784504544 1784504544 True ************************************************************ 2039217328240 2039217328176 2039217247376 2039217328240 False False False True '''Copy the code

Four.Guess you like

  1. Introduction of Python
  2. Python Pycharm Anacanda difference
  3. Python2.x and python3. x, how to choose?
  4. Python Configuration Environment
  5. Introduction to Python Hello World
  6. Python code comments
  7. Python Chinese encoding
  8. What is Anaconda? Anconda download the installation tutorial
  9. Pycharm prompt: this license **** has been cancelled
  10. Pycharm Sets the development template/font size/background color
  11. The Python list
  12. The Python tuple tuple

Python is different from ==

This article is published by the blog – Ape Say Programming Ape Say programming!