1.昨日内容回顾:
格式化输出
%s %d
%%
2.编码:
ascii 只能显示英文,特殊字符,数字。
万国码:unicode 最开始16位(两个字节),后来升级为32位(4个字节)。
升级:utf-8 utf-16 utf-32
utf-8: 英文8位,一个字节。
欧洲16位,两个字节。
亚洲24位,三个字节。
gbk:英文一个字节,中文两个字节
# #计算 1 - 2 + 3 ... + 99 中除了88以外所有数的总和
# 1-2+3.。。,。+99
# i=1
# sum=0
# while i <100:
# if i==88:
# i += 1
# continue
# if i%2!=0:
# sum=sum+i
# else:
# sum=sum-i
# i += 1
# print(sum)
什么是数据类型。
int 1,2,3用于计算。
bool:True,False,用户判断。
str:存储少量数据,进行操作
‘fjdsal‘ ‘二哥‘,‘`13243‘,‘fdshklj‘
‘战三,李四,王二麻子。。。。‘
list:储存大量的数据。
[1,2,3,‘泰哥‘,‘12353234‘,[1,2,3]]
元祖:只读。
(1,2,3,‘第三方‘,)
dict:字典{‘name‘:‘云姐‘,‘age‘:16}
字典{‘云姐‘:[],‘二哥‘:[200,200,200,。。。。。。]}
集合:{1,2,34,‘asdf‘}
‘‘‘i = 83
data = i.bit_length()
print (data)
# int→str
a = 1
s = str(a)
print (s,type(s))
#str-int
s1 = ‘1‘
a1 = int(s1)
print (a1,type(a1))
#int→bool值 int为0则返回False 非零则返回TRUE
a2 = 2
b = bool(a2)
print (b)
#bool---int False 0 True 1
a3 = False
b3 = int(a3)
print (b3)
# while True:
# pass
# while 1: 效率高
# pass
#str---bool ‘‘空字符串输出False 其余的都输出 True
a4 = ‘xyy2‘
b4 = bool(a4)
print(b4)
#str
s = ‘hdsvkhdbvji‘
#索引
s1 = s[0]
print(s1)
s2 = s[2]
print(s2)
s3 = s[-1]
print(s3)
#切片 顾头不顾尾
s = ‘hdsvkhdbvji‘
s4 = s[0:6]
print(s4)
s5 = s[8:2:-1]
print(s5)
s6 = s[0:-1]
print(s6)
s7 = s[:]
print(s7)
s8 = s[::-1]
print(s8)
s9 = s[9:8:-1]
print(s9)
‘‘‘
‘‘‘
s = ‘hdsvkhdbvji‘s[首:尾:步长]
s = ‘hdsvkhdbvji‘
s10 = s[0:8:2]
print(s10)
s11 = s[9:4:-3]
print(s11)
s12 = s[5::-1]
print(s12)
s13 = s[5::-2]
print(s13)
‘‘‘
#字符串的操作
#首字母大写
# a = ‘xubohua_say_Hello‘
# a1 = a.capitalize()
# print(a1)
# a2 = a.upper()
# print(a2)
# a3 = a.lower()
# print(a3)
# s_str = ‘ADSbjn‘
# you_input = input(‘请输入验证码,不区分大小写‘)
# if you_input.upper() ==s_str.upper():
# print(‘登陆成功‘)
# else:
# print(‘请重新输入‘)
#居中空白补充
# a4 = a.center(30,‘*‘)
# print(a4)
#大小写翻转
# a5 = a.swapcase()
# print(a5)
#每个隔开(特殊字符或者数字)的单词首字母大写
# a = ‘xubohua_say_Hello‘
# a6 = a.title()
# print(a6)
# a = ‘xbh\tb‘
# a7 = a.expandtabs()
# print(a7)
# s = ‘alex\tsir‘
# s6 = s.expandtabs()
# print(s6)
# a = ‘xbh徐博华‘
# l = len(a)
# print(l)
#以什么开始结尾 可以切片
# a = ‘xubohua_say_Hello‘
# a9 = a.startswith(‘xu‘,0,5)
# print(a9)
#find 通过元素找索引,找不到返回-1
# index通过元素找索引,找不到报错
# a = ‘xubohua_say_Hello‘
# b = a.find(‘z‘)
# b1 =a.index(‘z‘)
# print(b)
# print(b1)
#strip 默认删除前后空格
#strip rstrip lstrip
# a = ‘%xubohua_say_Hello%‘
# b = a.rstrip(‘%‘)
# print(b)
# s = ‘ *a%lexWUsi* r%‘
# s91 = s.strip(‘ %*‘)
# print(s91)
# username = input (‘请输入密码:‘).strip()
# if username == ‘徐博华‘:
# print(‘欢迎‘)
# else:
# print(‘请重新输入密码‘)
# s = ‘alexaa wusirl‘
# s10 = s.count(‘a‘)
# print(s10)
#split 以什么分割,最终形成一个列表此列表不含有这个分割的元素。rsplit
# ret9 = ‘title,Tilte,atre,‘.split(‘t‘)
# print(ret9)
# ret91 = ‘title,Tilte,atre,‘.rsplit(‘t‘,1)
# print(ret91)
#format的三种玩法 格式化输出
# s = ‘我叫{},今年{},爱好{},再说一下我叫{}‘.format(‘太白‘,36,‘girl‘,‘太白‘)
# print(s)
# name = input(‘请输入名字:‘)
# s = ‘我叫{0},今年{1},爱好{2},再说一下我叫{0}‘.format(name,36,‘girl‘)
# print(s)
# name = input(‘请输入名字:‘)
# s = ‘我叫{name},今年{age},爱好{hobby},再说一下我叫{name}‘.format(age=18,name=name,hobby=‘girl‘)
# print(s)
# s = ‘来看待街坊邻居复合大师街坊法好的撒见客户‘
# s11 = s.replace(‘街坊‘,‘老王‘,1)
# print(s11)
#
# s = ‘fhdsklfds‘
# for i in s:
# print(i)
# s = ‘fdsa苍井空fdsalk‘
# if ‘苍井空‘ in s:
# print(‘您的评论有敏感词...‘)