python_数据类型
什么数据类型。
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'}
3,int。
4,bool。
5,str。
一、int类型
i = 100 print(i.bit_length()) ''' bit_length 1 0000 0001 1 2 0000 0010 2 3 0000 0011 2 '''
二、bool类型
#bool True False #int ----> str i = 1 s = str(i) #str ---> int s = '123' i = int(s) #int ----->bool 只要是0 ----》False 非0就是True i = 3 b = bool(i) print(b) #bool----> int #True 1 #False 0 ''' ps: while True: pass while 1: 效率高 pass ''' #str --->bool #s = "" -----> False #非空字符串都是True #s = "0" -----> True # s # if s: # print('你输入的为空,请重新输入') # else: # pass
三、str类型
#字符串的索引与切片 ''' s = 'ABCDLSESRF' #索引 # s1 = s[0] # print(s1) # s2 = s[2] # print(s2) # s3 = s[-1] # print(s3) # s4 = s[-2] # print(s4) # #ABCD 切片 :顾头不顾尾 # s5 = s[0:4] # print(s5) # s6 = s[0:-1] # print(s6) # s7 = s[:] # s8 = s[0:] # print(s7,s8) # s9 = s[0:0] s = 'ABCDLSESRF' # s[首:尾:步长] # s10 = s[0:5:2] # print(s10) s11 = s[4:0:-1] print(s11) s12 = s[3::-1] print(s12) s13 = s[3::-2] print(s13) s = 'ABCDLSESRF' s14 = s[-1::-1] print(s14) s15 = s[::-1] print(s15) ''' #字符串的操作 s = 'alexWUsir' s1 = s.capitalize() # 首字母大写 # print(s1) # 全大写,全小写 s2 = s.upper() s21 = s.lower() # print(s2,s21) ''' s_str= 'acEQ1' you_input =input('请输入验证码,不区分大小写') if s_str.upper() == you_input.upper(): print('输入成功') else: print('请重新输入') ''' #大小写翻转 # s3 = s.swapcase() # print(s3) # 每个隔开(特殊字符或者数字)的单词首字母大写 # s = 'alex*egon-wusir' # s4 = s.title() # print(s4) # s = 'fade,crazy*w4rri0r_songsong node_3' # s4 = s.title() # print(s4) #居中,空白填充 # s = 'alexWUsir' # s5 = s.center(20,'~') # print(s5) # s = 'alex\tsir' # s6 = s.expandtabs() # print(s6) # s = 'alex二哥' # #公共方法 # l = len(s) # print(l) #以什么开头结尾 endswith # s = 'alexWUsir' # s7 =s.startswith('alex') # s71 = s.startswith('e',2,5) # print(s71) ''' if s7: pass elif s.startswith('bl'): pass print(s7) ''' # find 通过元素找索引,找不到返回-1 # # index通过元素找索引,找不到报错 # s = 'alexWUsir' # s8 = s.find('A') # s81 = s.index('A') # print(s81,type(s8)) #strip rstrip lstrip # s = 'alexWUsir%' # s9 = s.strip('%') # print(s9) # s = ' *a%lexWUsi* r%' # s91 = s.strip(' %*') # print(s91) # strip 默认删除前后空格 # username = input('请输入名字:').strip() # if username =='春哥': # print('恭喜春哥发财') # s = 'alexaa wusirl' # s10 = s.count('al') # print(s10) # split str ---->list # s = ';alex;wusir;taibai' # l = s.split('a') # print(l) #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('您的评论有敏感词...')