1.编码的起源
ACSLL编码:电脑起源于美国,最初的编码只包含了美国的日常字符.
00000001 8bit 1bytes
GBK:国标码:每个国家都能使用自己国家的编码,但是不同国家间不兼容.
00000000 00000001 16bit 2bytes
Unicode:万国码,包含所有国家.40多亿的bit,太浪费.
00000000 00000000 00000000 00000001 32bit 4bytes
UTF-8:可边长的编码,最短的是8位
美国:00000001 8bit 1bytes
东欧:00000000 00000001 16bit 2bytes
中国:00000000 00000000 00000001 24bit 3bytes
>2存储和传输的单位换算
8bit = 1bytes
1024bytes = 1KB
1024KB = 1MB
1024MB = 1GB
1024GB = 1TB
1024TB = 1PB
1024PB = 1EB
1024EB = 1ZB
1024ZB = 1YB
1024YB = 1NB
2.布尔值
>3bool功能 s = 100 print(bool(s)) # True s1 = 0 print(bool(s1)) # False s2 = True print(int(s2)) # 1 s3 = False print(int(s3)) # 0 # 有上述代码可以看出,在int和bool之间是可以互相转换的. # 转换得出以下结论: # 当int的值为0时,转换bool为False # 当int的值不为0时,转换bool为True # 当bool的值为False时,转换int值为0 # 当bool的值为True时,转换int的值为1 # 0代表False,非0代表True # s4 = "王剑威" print(bool(s4)) # True s5 = " " print(bool(s5)) # True s6 = "" print(bool(s6)) # False # 当str和bool转换时 # 有字符串就是True # 空就是False
3.字符串常用操作
>4字符串功能 #upper 全部小写变大写 s = "superman" print(s.upper()) # SUPERMAN #lower 所有的大写变小写 s1 = "SUPERMAN" print(s1.lower()) # superman #swapcase 将字符串中的大写变小写,小写变大写 s2 = "sUPerMan" print(s2.swapcase()) # SupERmAN #capitalize 首字母变大写,其他变小写 s3 = "SUPERMAN" print(s3.capitalize()) # Superman #center 居中,用指定字符填充两端 s4 = "superman" print(s4.center(20,"*")) # ******superman****** #strip 只是去除两端的空格 s5 = " super man " print(s5.strip()) # super man #replace 替换 s6 = "superman" print(s6.replace("man","woman")) # superwoman #split 切割,切割完的会被存储在列表中,用什么切割就会损失什么.当用最边上的值切割是,在列表中会产生一个空的值 s7 = "superman" print(s7.split("e")) # ['sup', 'rman'] # 当用最边上的值切割是,在列表中会产生一个空的值 s8 = "superman" print(s8.split("s")) # ['', 'uperman'] #format 格式化输出 #方法一: a = "我是{},今年{},我在{}".format("superman",18,"BeiJing") print(a) # 我是superman,今年18,我在BeiJing #方法二 name = "superman" age = 18 add = "BeiJing" a = "我是{a},今年{b},我在{c}".format(a=name,b=age,c=add) print(a) # 我是superman,今年18,我在BeiJing #startswith 判断某个字符串是不是以某个字符打头 s9 = "superman" print(s9.startswith("s")) # True #endswith 判断某个字符串是不是以某个字符结尾 print(s9.endswith("n")) # True #count 统计某个字符串出现的次数 s10 = "111222333" print(s10.count("1")) # 3 #index 查看某个字符的索引值 s10 = "superman" print(s10.index("u")) print(s10.index("uper")) # 1 # 1 #len() 查看字符串的长度,int类型没有长度 s11 = "superman" print(len(s11)) # 8