Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use python push mode

2025-01-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Most people do not understand the knowledge points of this article "python guidance how to use", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "python guidance how to use" article.

1. Dict derived list1 = ['name',' age', 'gender'] list2 = [' zmz','20, 'boy'] # Dictionary derived-quickly merge lists into dictionaries, or extract target data from dictionaries # cases 1-key is a number, value is the square of this number 1 = {I * * 2 for i in range (1,5)} print (dict1) # example 2-merge two lists Two lists of the same length dict2 = {list1 [I]: List2 [I] for i in range (len (list1))} print (dict2) # if the length of two lists is different Then take len (short list) # example 3-extract data from the dictionary dict3 = {'Mac': 10000,' Dell': 6599, 'HP': 6999,' Lenovo': 5799, 'Acer': 4599} print (dict3.items ()) counts = {key: value for key Value in dict3.items () if value > 6000} print (counts) II. List derivation "" derivation (generation)-- is used to simplify code deduction inclusion: 1. List derivation 2. Dictionary derivation 3. Set deductive "" # create a regular list or control a regular list with an expression list1 = [] # while implementation I = 0while I < 10: list1.append (I) I + = 1print (list1) # for implementation list2 = [] for i in range (10,20,1): list2.append (I) print (list2) # deductive implementation list3 = [i for i in range (- 9,2) 1)] the I on the left of # for is the return value Of course, to create a list, use [] print (list3) print (sum ([2 * * i for i in range (100)]) 3. Set derivation # set derivation-- mainly used to create collections based on the list list1 = [2,3,4,2,5,3] set1 = {I * * 2 for i in list1} print (set1) T1 = (10,20,30,40) 50) print (T1) T2 = (I * 2 for i in T1) print (T2) # cannot be printed. 4. With if derivation "create an even list of 0-10" # method-list1 = [i for i in range (0,11) 2)] print (list1) # method II list2 = [] for i in range (11): if I% 2 = = 0: list2.append (I) print (list2) # method 3 list3 = [i for i in range (11) if I% 2 = = 0] # the list derivation is actually print (list3) V derived from the simplification of for cycle, list = [] for i in range (1) with for 3): for j in range (3): list.append ((I, j)) print (list) print ("=") list1 = [(I, j) for i in range (5) for j in range (5)] # for loop nesting count = 0for I in list1: count + = 1 print (I, end='') if count% 5 = = 0: print () above is the content of this article on "how to use python deduction" I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report