current position:Home>How IOS developers learn python programming 3-operator 2
How IOS developers learn python programming 3-operator 2
2022-01-31 04:41:32 【Sissy's father】
This is my participation 11 Yue Gengwen challenges 3 God , Check out the activity details :2021 The last time Gengwen challenge .
member operator
in
And not in
yes Python
Unique operators ( It's all lowercase ). Used to determine whether an object belongs to a collection , Very fast . Back to True
perhaps False
.
- Judge
a
Whether inlist1
In the list :
list1 = [1, 2, 3, 4, 5]
a = 1
for i in list1:
if i == a:
print("a stay list1 in ")
else:
print('a be not in list1 in ')
flag = False
for i in list1:
if i == a:
flag = True
break
if flag:
print("a yes list1 One of the elements of ")
else:
print("a No list1 The elements of ")
# If you use in Operator , There's no need for such trouble
list1 = [1, 2, 3, 4, 5]
a = 1
if a in list1:
print("a yes list1 One of the elements of ")
else:
print("a No list1 The elements of ")list1 = [1, 2, 3, 4, 5]
a = 1
for i in list1:
if i == a:
print("a stay list1 in ")
else:
print('a be not in list1 in ')
flag = False
for i in list1:
if i == a:
flag = True
break
if flag:
print("a yes list1 One of the elements of ")
else:
print("a No list1 The elements of ")
# If you use in Operator , There's no need for such trouble
list1 = [1, 2, 3, 4, 5]
a = 1
if a in list1:
print("a yes list1 One of the elements of ")
else:
print("a No list1 The elements of ")list1 = [1, 2, 3, 4, 5]
a = 1
for i in list1:
if i == a:
print("a stay list1 in ")
else:
print('a be not in list1 in ')
flag = False
for i in list1:
if i == a:
flag = True
break
if flag:
print("a yes list1 One of the elements of ")
else:
print("a No list1 The elements of ")
# If you use in Operator , There's no need for such trouble
list1 = [1, 2, 3, 4, 5]
a = 1
if a in list1:
print("a yes list1 One of the elements of ")
else:
print("a No list1 The elements of ")
Copy code
Identity operator
Python
Characteristic grammar ( It's all lowercase ):
is
Used to judge whether the reference of two variables is the same object ( You can useid()
Get objects ).is not
opposite .
️ Be careful : is
And comparison operators ==
The difference between :
==
Used to determine whether the values of objects referenced by variables are equal .
>>> a = [1,2,3]
>>> b = [1,2,3]
>>> a is b
False
>>> a == b
True
>>> a = 2
>>> b = 2.0 # It can be done by id() Check the memory address
>>> a is b
False
>>> a == b
True
Copy code
Ternary operator
python
The representation of the trinary operator in :
True_statements if expression else False_statements
Copy code
for example :
a = 1
b = 2
if a+b>3:
print(a+b)
else:
print(b-a)
a+b if a+b>3 else b-a # Ternary operator
Copy code
Operator priority
The following table lists all operators from the highest to the lowest priority . Operators with higher priority have priority in calculation or processing , The same level is calculated from left to right ( Except for assignment operators , It's in right to left order ):
Operator | describe |
---|---|
** | Index ( The highest priority ) |
~ + - | Flip by bit , One yuan plus sign and minus sign ( The last two methods are called [email protected] and [email protected]) |
* / % // | ride 、 except 、 modulus 、 Divide and conquer |
+ - | Add 、 Subtraction |
>> << | Move right 、 Move left |
& | position AND |
^ | |
<= < > >= | Comparison operator |
<> == != | Equals operator |
= %= /= //= -= += *= **= | Assignment operator |
is is not | Identity operator |
in not in | member operator |
not or and | Logical operators |
copyright notice
author[Sissy's father],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/01/202201310441294210.html
The sidebar is recommended
- [Python from introduction to mastery] (V) Python's built-in data types - sequences and strings. They have no girlfriend, not a nanny, and can only be used as dry goods
- Does Python have a, = operator?
- Go through the string common sense in Python
- Fanwai 4 Handling of mouse events and solutions to common problems in Python opencv
- Summary of common functions for processing strings in Python
- When writing Python scripts, be sure to add this
- Python web crawler - Fundamentals (1)
- Pandas handles duplicate values
- Python notes (23): regular module
- Python crawlers are slow? Concurrent programming to understand it
guess what you like
-
Parameter passing of Python function
-
Stroke tuple in Python
-
Talk about ordinary functions and higher-order functions in Python
-
[Python data acquisition] page image crawling and saving
-
[Python data collection] selenium automated test framework
-
Talk about function passing and other supplements in Python
-
Python programming simulation poker game
-
leetcode 160. Intersection of Two Linked Lists (python)
-
Python crawler actual combat, requests module, python to grab the beautiful wallpaper of a station
-
Fanwai 5 Detailed description of slider in Python opencv and solutions to common problems
Random recommended
- My friend's stock suffered a terrible loss. When I was angry, I crawled the latest data of securities with Python
- Python interface automation testing framework -- if you want to do well, you must first sharpen its tools
- Python multi thread crawling weather website pictures and saving
- How to convert pandas data to excel file
- Python series tutorials 122
- Python Complete Guide - printing data using pyspark
- Python Complete Guide -- tuple conversion array
- Stroke the list in python (top)
- Analysis of Python requests module
- Comments and variables in Python
- New statement match, the new version of Python is finally going to introduce switch case?
- Fanwai 6 Different operations for image details in Python opencv
- Python crawler native code learning (I)
- Python quantitative data warehouse building series 2: Python operation database
- Python code reading (Part 50): taking elements from list intervals
- Pyechart + pandas made word cloud pictures of 19 report documents
- [Python crawler] multithreaded daemon & join() blocking
- Python crawls cat pictures in batches to realize thousand image imaging
- Van * Python | simple crawling of a planet
- Input and output of Python practice
- Django ORM details - fields, attributes, operations
- Python web crawler - crawling cloud music review (3)
- Stroke list in python (bottom)
- What cat is the most popular? Python crawls the whole network of cat pictures. Which one is your favorite
- [algorithm learning] LCP 06 Take coins (Java / C / C + + / Python / go / trust)
- Python shows the progress of downloading files from requests
- Solve the problem that Django celery beat prompts that the database is incorrectly configured and does not support multiple databases
- Bamboolib: this will be one of the most useful Python libraries you've ever seen
- Python quantitative data warehouse construction 3: data drop library code encapsulation
- The source code and implementation of Django CSRF Middleware
- Python hashlib module
- The cover of Python 3 web crawler development (Second Edition) has been determined!
- The introduction method of executing Python source code or Python source code file (novice, please enter the old bird and turn left)
- [Python basics] explain Python basic functions in detail, including teaching and learning
- Python web crawler - crawling cloud music review (4)
- The first step of scientific research: create Python virtual environment on Linux server
- Writing nmap scanning tool in Python -- multithreaded version
- leetcode 2057. Smallest Index With Equal Value(python)
- Bamboolib: this will be one of the most useful Python libraries you've ever seen
- Python crawler actual combat, requests module, python realizes capturing a video barrage