current position:Home>Python interface automation test framework (basic) -- common data types Dict
Python interface automation test framework (basic) -- common data types Dict
2022-01-31 05:15:08 【I am the white moonlight you can't get】
「 This is my participation 11 The fourth of the yuegengwen challenge 6 God , Check out the activity details :2021 One last more challenge 」
Preface
The next two articles are about variable data types , Finally dict, From the author's experience , The order of common data types should be dict、list、str、tuple、bool( Often used as a judgment condition )、int.< Of course, others have different views >
Dictionaries
keyword :dict, Symbol {}, It is a variable container model and can store any type of object ; With key:value Save data in the form of ,key: only , Non iteratable data types :int float Boolean value Tuples &value: Can contain any data type :int float str list tuple dict Boolean value
Create a dictionary
- Code demonstration : The immutable data type is key
dict_1={} # Represents an empty dictionary
dict_2={"a":"b"}
dict_3={(1,):2,1.1:2,True:False}
Copy code
Value method
dict_1={"k1":"v1"}
dict_1[key] # That is, get the specified key Value
dict_1.get(key) # obtain key Value , There is no return none, It is more flexible than the previous dictionary
Copy code
Additions and deletions
- Add to change : The assignment operation , If key non-existent , It's new , The opposite is to modify
dict_1={}
dict_1["key"]="value"
print(dict_1)={"key":"value"}
Copy code
- dict Delete except del Others are implemented through functions
dict_1={"k1":"v1","ke":"ve"}
v=dict_1.pop("k1") # Delete function , And return to delete key Of value
print(v) # Output :v1
dict_2=dict_1.popitem() # Randomly delete a group key:value And back to tuple
print(dict_2) # Output :("ke","ve")
clear() # Empty dictionary no return value , primary dict_1 Will become {}
del dict_1[key] Delete the specified key
Copy code
- update The update function can only be dict type
dict1={"k1":"v1"}
dict1.update({1:2})
print(dict1) # Output :{'k1': 'v1', 1: 2}
Copy code
Built in functions
- items(), among dict The key value pair of becomes an element of a tuple , return list form , But it's not list data type , It is dict_items
dict1={"ke":"ve","k1":"v1"}
li=dict1.items()
print(li) # Output :dict_items([{"ke":"ve"},{"k1":"v1"}])
Copy code
- values(), obtain dict All of the objects value, With list form , But not of any kind , It is dict_values
dict1={"ke":"ve","k1":"v1"}
li=dict1.values()
print(li) # dict_values(['ve', 'v1'])
Copy code
- keys(), obtain dict All of the objects key, With list form , But not of any kind , It is dict_keys
dict_1={"ke":"ve","k1":"v1"}
li=dict_1.keys()
print(li) # Output :dict_keys(['ke', 'k1'])
Copy code
- len() Calculate the length of the variable , stay dict Statistics in key Total of
- has_key(key) Used to determine key Whether there is dict In the object , Otherwise return to False
dict1={"k1":"1","a":"b","k1":"2"}
b=dict1.has_key("kk")
# Python 3.X The method is not supported .
print b # Output :False
Copy code
Extended features
We know dict Type of key Must be the only , Immutable data types , If key Duplicate occurs , It only remembers the last value
dict1={"k1":"1","a":"b","k1":"2"}
print(dict1) # Output :{"k1":"2","a":"b"}
Copy code
copyright notice
author[I am the white moonlight you can't get],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/01/202201310515059171.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