Home  >  Article  >  Backend Development  >  Python operators - frequently used member operators (example analysis)

Python operators - frequently used member operators (example analysis)

乌拉乌拉~
乌拉乌拉~Original
2018-08-13 17:19:061949browse

In today’s article, we will talk about the member operators among Python operators. I hope this article can help you reading.

Member operators:

In addition to some of the operators mentioned before, Python also supports member operators. The test example contains a series of Members, including strings, lists or tuples, as shown below:

Python operators - frequently used member operators (example analysis)

The following examples demonstrate the operation of all Python member operators:

#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
a = 10
b = 20
list = [1, 2, 3, 4, 5 ];
 
if ( a in list ):
   print "1 - 变量 a 在给定的列表中 list 中"
else:
   print "1 - 变量 a 不在给定的列表中 list 中"
 
if ( b not in list ):
   print "2 - 变量 b 不在给定的列表中 list 中"
else:
   print "2 - 变量 b 在给定的列表中 list 中"
 
# 修改变量 a 的值
a = 2
if ( a in list ):
   print "3 - 变量 a 在给定的列表中 list 中"
else:
   print "3 - 变量 a 不在给定的列表中 list 中"

The output result of the above example is as follows:

1 - 变量 a 不在给定的列表中 list 中
2 - 变量 b 不在给定的列表中 list 中
3 - 变量 a 在给定的列表中 list 中

The above content is the member operator among python operators. I hope this article can be helpful to you who are learning python.

The above is the detailed content of Python operators - frequently used member operators (example analysis). For more information, please follow other related articles on the PHP Chinese website!

Statement:
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