day4 class work
阿新 • • 發佈:2017-10-24
今天 老師 首字母 格式化 dig rst alt ges ace
今天是第四天,一如既往的每天都有不會做的內容,然後還是那種你使勁的絞盡腦汁都想不出來的問題,而且還得是別人提示著,講著,演示著才能明白的,過後自己還得使勁捉摸才能慢慢吃透。一開始還挺順利的,還以為自己終於能夠跟上一點點步伐了呢,誰知道自己高興太早了,後面的題都不會做。。。每天都是滿滿的不會做,不行,搞不定,太受挫了。。。。心酸!一想到自己以後還有幾十年的人生要過,就不能輕易的投降了,硬著頭皮上吧,就像老師說的看不懂就硬看,逼出來就好了。
#1,索引和切片 [起始位置:結束位置:步長]
# s1 = ‘python全棧8期‘ #索引從0開始 [索引(下標,index)]
# print(s1[0])
# print(s1[3])
# print(s1[5])
# print(s1[6])
# print(s1[-1])
#切片 顧頭不顧腚
# print(s1[0:6])
# print(s1[6:10])
# print(s1[6:11])
# print(s1[6:])
# print(s1[1:5])
#pto #s1 = ‘python全棧8期‘
# print(s1[0:5:2])
# print(s1[0:7:3])
#倒取值:加步長
# print(s1[3::-1])
# print(s1[5:0:-2])
# print(s1)
#不變
# s2 = s1[0:6]
# print(s2) ret = ‘alexS‘
#字符串的使用方法。
# * capitalize 首字母大寫,其他的全小寫 ret1 = ret.capitalize()
# print(ret,ret1)
# * upper,lower ret2 = ret.upper() ret3 = ret.lower()
# print(ret2,ret3)
‘‘‘ code = ‘A‘
your_code = input(‘請輸入驗證碼,不區分大小寫‘)
if your_code == ‘A‘ or your_code == ‘a‘:
print(‘您輸入的正確‘)
else:print(‘請重新輸入‘)
code = ‘adeE‘.upper()
your_code = input(‘請輸入驗證碼,不區分大小寫‘).upper()
if your_code == code:
print(‘您輸入的正確‘)
else:print(‘請重新輸入‘) ‘‘‘
# 大小寫翻轉
# ret4 = ret.swapcase()
# print(ret4)
# ret11 = ‘alex+jin wu‘
#以特殊符號或者空格隔開,每一個字符串首字母大寫 title()
# print(ret11.title())
# * 居中 ret = ‘alexS‘
# print(ret.center(20))
# print(ret.center(20,‘*‘))
# *******alexS********
# * 返回bool值 startswith endswith
# ret5 = ret.startswith(‘a‘)
# ret5 = ret.startswith(‘ale‘)
# ret5 = ret.startswith(‘alexS‘)
# ret5 = ret.startswith(‘l‘,1,3)
# 切片 # print(ret5)
# ret6 = ret.endswith(‘S‘,-2,)
# print(ret6) ret22 = ‘alexS,aeaeQ‘
# ** count
# ret7 = ret22.count(‘a‘)
# ret7 = ret22.count(‘ale‘)
# 整體與個體
# ret7 = ret22.count(‘W‘)
# 0
# ret7 = ret22.count(‘a‘,0,7)
# 切片的count
# print(ret7)
# a2 = "qwaaaaaaaa\taa"
#\t前面的補全
# 默認將一個tab鍵變成8個空格,如果tab前面的字符長度不足8個,則補全8個,如果tab鍵前面的字符長度超過8個不足16個則補全16個,以此類推每次補全8個。
# ret8 = a2.expandtabs()
# print(ret8,len(ret8)) ret = ‘aleaxS‘
# * find 通過元素找到索引(找到第一個元素),找不到返回-1
# ret9 = ret.find(‘a‘)
# # ret9 = ret.find(‘W‘,0,5)
# print(ret9)
# #index 和find用法一模一樣,找不到元素,就會報錯
# ret10 = ret.index(‘w‘)
# print(ret10)
# * strip 去除字符串前後的空格及你想去除的元素
# ret11 = ‘ alex ‘.strip()
# print(ret11)
‘‘‘ name = ‘alex‘
username = input(‘請輸入你的用戶名:‘).strip()
if username == name :
print(‘登錄成功‘) ‘‘‘
# ret11 = ‘ alex ‘.lstrip()
# print(ret11)
# ret11 = ‘ alex ‘.rstrip()
# print(ret11)
#一:
# ret12 = ‘asldfkjafa‘.strip(‘a‘)
# print(ret12)
#二:
# ret13 = ‘asldfkjafa‘.strip(‘sa‘)
# print(ret13)
# ret13 = ‘asldfkjafa‘.strip(‘salf‘)
# print(ret13)
# ret14 = ‘asldfkajafa‘.strip(‘saWlf‘)
# print(ret14)
#split * 將字符串分割成列表
# ret15 = ‘jinxin alex wusir‘
# ret16 = ret15.split()
# print(ret16)
# ret15 = ‘jinxin,alex,wusir‘
# ret16 = ret15.split(‘,‘)
# print(ret16)
# ret15 = ‘title tle tlie‘
# ret16 = ret15.split(‘t‘)
# print(ret16)
# * 替換 replace
# ret18 = ‘粉紅色打開了粉紅色級第三粉紅色‘
# ret19 = ret18.replace(‘粉紅色‘,‘嫩綠色‘,1)
# print(ret19)
# 格式化輸出 format
#第一種:
# ret20 = ‘name:{},sex:{},身高:{}‘.format(‘alex‘,‘ladyboy‘,178)
# print(ret20)
#第二種:
# ret20 = ‘name:{0},sex:{1},身高:{2},name:{0}‘.format(‘alex‘,‘ladyboy‘,178)
# print(ret20)
#第三種:鍵值對
# ret20 = ‘name:{name},sex:{sex},身高:{high},name:{name}‘\
# .format(sex = ‘ladyboy‘,high = 178,name=‘alex‘)
# print(ret20)
# 判斷條件
# name=‘123‘
# print(name.isalnum())
#字符串由字母或數字組成
# print(name.isalpha())
#字符串只由字母組成
# print(name.isdigit())
#字符串只由數字組成 s = ‘aelsdskjl‘
# s = s[1:]
# print(s)
# print(len(s))
#測量長度
# index = 0
# while True:
# print(s[index])
# index += 1
# if index == len(s):break
#for 變量 in 可叠代對象
# for i in s:
# print(i) s = ‘fs4dkjla123fkj2dsa‘
count = 0
for i in s:
if i.isdigit():
count += 1
else:print(666)
print(count)
day4 class work