python之代码积累 100行
Posted 菜鸟鸭
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python之代码积累 100行相关的知识,希望对你有一定的参考价值。
s1=‘‘ print(bool(s1)) #False s1=‘ ‘ print(bool(s1)) #True name=input(‘>>>‘) if name: print(‘666‘) else: print(‘333‘) print(str(True),str(False)) #True False print(type(True),type(False)) #<class ‘bool‘> <class ‘bool‘> s1=‘python1期骑士计划‘ s2=s1[0] print(s2,type(s2)) #p <class ‘str‘> s3=s1[-1] print(s3) #划 s5=s1[0:6] s6=s1[:6] s7=s1[6:] s8=s1[:5:2] s9=s1[1::2] print(s5) #python print(s6) #python print(s7) #1期骑士计划 print(s8) #pto print(s9) #yhn期士划 name=‘oldBay‘ print(name.capitalize()) #Oldbay print(name.center(20,‘*‘)) #*******oldBay******* print(name.upper()) #OLDBAY print(name.lower()) #oldbay username=input(‘请输入 用户名:‘) code=‘ADfer‘.upper() your_code=input(‘请输入验证码:‘).upper() if username==‘alex‘ and your_code==code: print(‘账号密码及验证码输入正确‘) name=‘pYtHon‘ print(name.startswith(‘o‘)) # False print(name.startswith(‘pY‘)) # False print(name.startswith(‘Y‘,1)) # True print(name.startswith(‘Yt‘,1,5)) # True print(name.startswith(‘pYtHon‘) )# True print(name.endswith(‘n‘)) #True print(name.endswith(‘on‘)) #True print(name.endswith(‘n‘,5)) #True print(name.endswith(‘on‘,1,6)) #True print(name.endswith(‘pYtHon‘)) #True print(name.swapcase()#PyThON s1 = ‘alex wusir*taibai6nvshen‘ print(s1.title()) #Alex Wusir*Taibai6Nvshen name=‘ olDboY ‘ name1=‘*alex**‘ print(name.find(‘b‘)) #3 print(name.find(‘lD‘)) #1 print(name.find(‘w‘)) #-1 print(name.find(‘D‘,1,-1)) #2 print(name.index(‘b‘)) #3 print(name.index(‘lD‘)) # # print(name.index(‘w‘)) #报错 print(name.index(‘D‘,1,-1)) #2 print(name.strip()) #olDboY print(name.lstrip()) #olDboY print(name.rstrip()) #olDboY print(name1.strip(‘*‘)) #alex name2=‘weralexwqwe‘ print(name2.strip(‘erw‘)) #alexwq name=‘ oldBody ‘ print(name.lstrip()) print(name.rstrip()) username=input(‘请输入用户名:‘).strip() if username==‘alex‘: print(‘登陆成功....‘) s1=‘ alex wusir taibai‘ l1=s1.split() print(l1) #[‘alex‘, ‘wusir‘, ‘taibai‘] s=‘alex, wusir, taibai‘ print(s.split(‘,‘)) #[‘alex‘, ‘ wusir‘, ‘ taibai‘] s3=‘,alex,wusir,taibai‘ print(s3.split(‘,‘)) #[‘‘, ‘alex‘, ‘wusir‘, ‘taibai‘] s5=‘alexlwle‘ print(s5.split(‘l‘,1)) #[‘a‘, ‘exlwle‘] s5=‘alexlwle‘ print(s5.rsplit()) #[‘alexlwle‘] str1=‘alex‘ s2=‘*‘.join(str1) print(s2) #a*l*e*x str2=‘alex是创始人,alex很厉害,alex很帅‘ s3=str2.replace(‘alex‘,‘艾利克斯‘) print(s3) #艾利克斯是创始人,艾利克斯很厉害,艾利克斯很帅 s3=str2.replace(‘alex‘,‘艾利克斯‘,1) print(s3) #艾利克斯是创始人,alex很厉害,alex很帅 s1=‘我叫{},今年{},性别{}‘.format(‘小甲鱼‘,‘22‘,‘男‘) print(s1) s2=‘我叫{0},今年{1},性别{2},我依然叫{0}‘.format(‘小甲鱼‘,‘22‘,‘男‘) print(s2) s3=‘我叫{name},今年{age},性别{sex}‘.format(age=‘22‘,sex=‘男‘,name=‘小甲鱼‘) print(s3) name=‘taibai123‘ name1=‘a123‘ print(name.isalnum()) print(name1.isdigit()) print(name.isalpha()) name=‘alexaaa‘ print(name.count(‘a‘)) #4 print(len(name)) #7 s1 = ‘skdqwewwwwwdffkkbbdjdsbhdhs‘ i=0 while i<len(s1): print(s1[i]) i+=1 for i in s1: print(i) for i in s1: print(666)
以上是关于python之代码积累 100行的主要内容,如果未能解决你的问题,请参考以下文章
我用了100行Python代码,实现了与女神尬聊微信(附代码)
[工作积累] UE4 并行渲染的同步 - Sync between FParallelCommandListSet & FRHICommandListImmediate calls(代码片段