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 create and delete the list of Python

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

Share

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

This article mainly explains "how to create and delete the list of Python". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to create and delete the list of Python".

1. List definition:

Formally, all elements of the list are placed in a pair of square brackets "[]", separated by "," between two adjacent elements.

Content, you can put integers, real numbers, strings, lists, tuples, and so on any type of content in the list, and in the same list, the type of elements can be different, because there is no relationship between them.

two。 List creation and deletion create a list directly using the assignment operator # example: num = [7, 8, 10, 98230999] verse = ["ace force", "good words freehand brushwork", "pleasure to meet you"] text = [282836 "I am Jing Ruo Morninglight"] create an empty list # create an empty list emptylist emptylist = [] create a numerical list # you can use the list () function to directly convert the results looped out by the range () function into a list # for example: create a list of all even numbers between 10-20 (excluding 20) list (range (10jing20)) # print print out the result for [10pjong 12jin14] delete the list del listname # listname as the list name 3. Access list element # create list list1list1 = ["static", "Ruo", "Morning", "Light"] # output the entire list, use the print () function list1 = ["static", "if", "Morning", "Light"] print (list1) # to run as follows. Note that [] is also output ["static", "Ruo", "Morning", "Light"] # to access some elements, such as index 2. List1 = ["quiet", "if", "Morning", "Light"] print (list1 [2]) # the running result is as follows. Note that when outputting a single list element, there are no brackets. If it is a string, no morning exercises are output in quotation marks.

Topic: enter a certain day of the year to determine the day of the year: [input format: YYYY-MM-DD]

User_input = input ('input: year-month-day') Year = int (User_input.split ('-') [0]) # # get the year Month = int (User_input.split ('-') [1]) # # get the month Day = int (User_input.split ('-') [2]) # # get the day li = [31 days li = [31, 28, 31, 31, 31] # # the number of days in all normal months num = 0 # Record days if ((Year% 4 = = 0) and (Year% 100! = 0) or (Year% 400 = = 0): # # in leap years: li [1] = 29 # # change the number of days in February to 29for i in range (12): # # traversal months if Month > I + 1: # I starts at 0 If it is a certain day in May, the I cycle stops at 3, after 0-1-2-3 cycles, take 4 months, that is, all the days from 1-2-3-4 num + = li [I] # # sum the total number of days from January to April else: # # after quitting the if judgment, when the next cycle, iTunes 1 does not meet the conditions of if and enters the else Add the day of the last May to the total number of days num + = Day breakprint ('this day is the% d day of% d year'% (Year,num))

Thank you for your reading, the above is the content of "how to create and delete the list of Python". After the study of this article, I believe you have a deeper understanding of how to create and delete the list of Python. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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