Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of python list Analytic Formula

Shulou Source: shulou.com Published: 2022-06-01 05:18:55 09月25日 Update

This article shares with you the content of a sample analysis of the python list parsing. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

List analytic expression

For example, we have a series of fruit names, which are stored in the fruit list. If we want to change the contents of the list to uppercase, we can do it in many ways:

Fruit = ["apple", "pear", "orange", "banana"] the first: for i in range (len (fruit)): fruit [I] = fruit.upper () the simpler syntax: fruit = [x.upper for x in fruit]

What follows for in square brackets tells python that we need to enumerate all the elements in the fruit variable, where each element's name is x, and the first half capitalizes x upper ().

To do an exercise, the comments section can tell you what this code means:

Fruit = ["apple", "pear", "orange", "banana"] new_fruit = [x for x in fruit if x.startwith ("a")] Thank you for reading! This is the end of this article on "sample analysis of python list parsing". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Content examples analysis elements capitalization more articles good practical code sub-rules first half methods variables names meaning articles square brackets fruit Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MySQL MariaDB Xiaomi vpn