python基礎04
python基礎04
python2在編譯安裝時,可以通過參數 -----enable----unicode=ucs2 或 -----enable--unicode=ucs4
分別用於指定使用2個字節,4個字節表示一個Unicode字符。python3無法進行選擇,默認使用usc4.
查看當前python中表示Unicode字符串時占用的空間:
import sys
print(sys.maxunicode)
#如果值是65535,則表示使用usc2標準,即:2個字節表示
#如果值是1114111,則表示使用usc4標準,即:4個字節表示
昨日內容及作業講解
ASCII:字母,數字,特殊字符,1個字節,8位
Unicode:16位 兩個字節 升級32位 四個字節
utf -8:最少一個字節 8位表示。 英文字母8位 1個字節
歐洲16位,2個字節
中文24位,3個字節
gbk:中文2個字節,英文字母1個字節
int : bit_length()
bool : True False
str : str---->bool bool(str):‘ ‘------->False
str :
s = ‘alexsb‘
s1 = s[1]
s2 = s[1:3]
s3 = s[0:] s[:]
s4 = s[0:-1]
s5 = s[0:3:2]
s6 = s[2::2]
字符串的一些常用方法
upper()全大寫
lower()全小寫
find()通過元素找索引,找不到-1
index()通過元素找索引,找不到報錯
swpcase()大小寫翻轉
len()
replace(old,new,count)
isdigit()返回bool值
isapha()
isnumpha()
startwith endwith
title()首字母大寫
center()居中
strip() lstrip rstrip
split()
format()格式化輸出
{}
{0}{1}{2}{0}
{name}{age}{hobby} name = age + hobby
len()長度
count 計數
for i in 可叠代對象:
pass
python基礎04