python3 7基礎複習1

2021-10-08 13:52:17 字數 1678 閱讀 4973

序列:一種資料結構,它包含的元素都進行了編號(從0開始)

典型序列:列表、字串、元組

列表可修改,元組不可修改(一旦建立便固定)

列表方法:x.index(2)-返回2第乙個匹配項的索引位置

x.insert(3,2)-在索引3的位置處插入元素2

x.pop(2)-移除列表中的索引為2的元素(預設是最後乙個),並返回該元素的值

x.remove(2)-移除列表中2的第乙個匹配項

x.reverse()-反向存放

x.sort()-從小到大排序,修改原列表

x.sort(key=len)-根據元素長度排序

x.sort(reverse=true)-反向排序【從大到小】,x.sort(reverse=false)-正向排序【從小到大

y=x.sort() ❌ → y=x y.sort()

y=sorted(x)-原列表x不被修改,y排序

cmp(x,y)-compare,x>y返回1,x=

元組方法:

(4)-int,(4,)-元組,()-空元組

tuple(seq)-把序列轉換成元組

abs(-

10)#返回數字的絕對值

#out: 10

math.sqrt(25)

#out: 5

import cmath #complex math複數

cmath.sqrt(-25

)#平方根,可用負數

#out: 5j

float(5

)#將字串和數字轉換為浮點數

#out: 5.0

math.ceil(

5.1)

#ceil天花板,向上取整,返回值的型別為浮點數

math.floor(

5.1)

#floor地板,向下取整,返回值的型別為浮點數

round

(5.1

)#四捨五入,round(number[,ndigits])給定精度

pow.(2

,3)#2^3

#out: 8

pow.(2

,3,2

)#2^3%2

#out: 0

input

("what is your name?"

)#獲取使用者輸入

#out: 'gumby'

print

(str

("hello,world"))

#str與int、long一樣,是資料型別

#out: hello,world

print

(repr

("hello,world"))

#repr是函式,建立乙個字串,把引號中的內容全部列印出

#out: 'hello,world'

Python3 7安裝部署

教你如何在 centos 7 下編譯安裝 python 3.7 與 python 2.7.5 共存。環境 centos 7.6 x64 一 安裝python 3.7 wget 如果沒有wget命令,可以使用命令安裝 yum y install wget 安裝依賴包,避免安裝過程 現的 zipimpo...

linux環境安裝python3 7

我用的是linux centos 6 1 首先安裝依賴包,確認gcc是否安裝,可以用檢視 gcc version 2.如果沒有則進行安裝,需要sudo許可權 yum y install gcc 3.安裝其他依賴包 可以不安裝,但是可能會安裝過程中報錯 yum y install zlib devel...

python3 7無法安裝pyaudio?

習慣了用pip安裝python模組的人,今天試了一下安裝pyaudio。首先看官網,what?當時安裝anaconda tensorflow時候,已經把python公升級到3.7,現在用pip安裝pyaudio還不支援3.7.如果你用pip install pyaudio 提示error micro...