程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

0 basic learning python (9)

編輯:Python

stay python There are a few dedicated to dealing with numbers python function , Using these values can facilitate our processing of complex data

>>>dights=[1,2,3,4,5,6,7,8,9,0]
>>>min(dights)
0
>>>max(dights)
9
>>>sum(dights)
45

min Represents the minimum output is 0

max The output representing the maximum value is 9

sum The representation and output are 45

Let's learn about slicing .

We were talking about del When deleting, I said about slicing , To create slices , You need to specify the index of the first element and the last element , Of course and function range(), The same index you want to output must be a digit after the number .

for example

classnumbers=['zhang','wang','su','meng','fan','chu']
print(classnumbers[0:3])
['zhang','wang','su']

from 0 The index starts from the first start to the third end . When you type [0:4] Will output from ‘zhang’ To ‘meng’

When python If there is no first index, it will automatically start from the beginning of the list .

for example

classnumbers=['zhang','wang','su','meng','fan','chu']
print(classnumbers[:5])
['zhang','wang','su','meng','fan']

You can use a similar method when you want the slice to terminate at the end of the list , Add that you want to extract the third element from the list , To the last element .

classnumbers=['zhang','wang','su','meng','fan','chu']
print(classnumbers[2:])
['su','meng','fan','chu']

Output the list directly to the end .

Or just want the last three in the list , At this time, we need to input

classnumbers=['zhang','wang','su','meng','fan','chu']
print(classnumbers[-3:])
['meng','fan','chu']

In some cases, we need to use slicing in combination with others for It can also be used in the loop .

classnumbers=['zhang','wang','su','meng','fan','chu']
for classnumber in classnumbers[:3]:
print(classnumber.title())
Zhang
Wang
Su


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved