python实训day1
作者:互联网
作业:
# (1)移除name变量对应的值两边的空格 name =" aleX" print(name.strip()) # (2)判断name变量对应的值是否以"al"开头,并输出结果 # 此时是以空格为开头 print(name.startswith("al")) # (3)判断name变量对应的值是否以"x"结尾,并输出结果 print(name.endswith("X")) # (4)将name变量对应的值中的"1"替换为"p",并输出结果 name=name.replace("l","p") print(name) # (5)将name变量对应的值根据"1"分割,并输出结果 list=name.split('l') print(list) list1=name.split('p') print(list1) # (6)将name变量对应的值变大写,并输出结果 print(name.upper()) # (7)将name变量对应的值变小写,并输出结果 print(name.lower()) # (8)请输出name变量对应的值的第2个字符 print(name[2]) # (9)请输出name变量对应的值的前3个字符 print(name[0:4]) # (10)请输出name变量对应的值的后2个字符 print(name[2:4]) # (11)请输出name变量对应的值的"e"所在的索引的位置 print(name.find('e')) # (12)获取子序列,去掉最后一个字符,如oldboy则获取oldbo print(name[0:len(name)-1])
总结:
# 数字类型 # 整型int # number = 100 # int(100) # number2 = int(100) # print(number) # print(number2) # 浮点型 float # sal = 15.0 # float(15.0) # sal2 = float(15.0) # print(sal) # print(sal2) # 字符串类型 # name = 'tank' # name2 = "tank" # content = ''' # 1r1r1r # 21r12r1 # r12r # 12r1r21 # r12r1r2 # 12r1r # ''' # # print(name, name2, content) # python中字符串可以相加、相乘 # print('tank ' * 5) # print('tank' + 'jam') # print('tank', 'jam') # 列表类型 # []括号内以逗号隔开,可存放多个不同类型的值。 # list1 = ['张曼曼', 'tank', '涂懿磊', 11, 1.0, ['jason', 200]] # print(list1[0]) # print(list1[5][0]) # 字典类型 # 在{}内,都逗号隔开,可存放多个值,每个值以key: value的形式存储 # 存 # dict1 = {'name': "tank", "age": 18} # {name="tank", "age"=18} # 取 # print(dict1["name"]) # 布尔类型 # True or False # print(10 == 10) # True # print(10 == 11) # False # 注意: 所有数据类型都自带布尔, 0、None、空都为False # if 0: # print('111') # # if None: # print('111') # # if []: # print('111') # # else: # print('222') # 格式化输出 # 可以在输出时给字符串类型做一次替换 # %s占位符,%d可以替换数字类型 # number = input('请输入:') # str1 = ''' # 尊敬的用户,您的话费余额为%s元。 # ''' % number # # print(str1) # for循环 # list1 = [1, 2, 3, 4, 5] # for line in list1: # print(line) # for line in range(1, 10): # print(line) # dict1 = {'name': "tank", "age": 18} # for key in dict1: # print(key) # print(dict1[key])
# ''' # str1='my name is xxx,my age is 18' # #祛除左右空格strip # print(str1) # print(str1.strip()) # #切分split # list2=str1.split(' ') # print(list2) # str2='my name is xxx,my age is 18' # for line in str2: # print(line,end=" ") # str6 = 'my name in Tank' # print(str6.lower()) # print(str6.upper())#lower 小写 upper 大写 # print(str6.startswith('my')) #startswith 判断前面 endswith 判断后面 # print(str6.startswith('My')) # print(str6.endswith('tank')) # #fomat 三种玩法 # str7 = 'my name in {},my age is{}' # str7=str7.format('tank',18) # print(str7) # # str7='my name in {1},my age is{2}' # str7=str7.format('tank',18,111) # print(str7) # # str7='my name in {name},my age is{age}' # str7=str7.format(name='tank',age=18) # print(str7) # ''' # # join 对列表中的数据按照某种标识拼接 拼接要为字符串类型 # name ='tank' # age='20' # print(':'.join([name,age])) # #replace # str8 ='old new' # str8=str8.replace('old','new') # print(str8) # #isdigit 判断字符串是否为数字 # ID =input('请输入') # print(ID) # print(ID.isdigit()) list1=['tank',18,'womale',3.0,9] print(list1[4]) print(list1[-2]) # ''' # str1='my name is xxx,my age is 18' # #祛除左右空格strip # print(str1) # print(str1.strip()) # #切分split # list2=str1.split(' ') # print(list2) # str2='my name is xxx,my age is 18' # for line in str2: # print(line,end=" ") # str6 = 'my name in Tank' # print(str6.lower()) # print(str6.upper())#lower 小写 upper 大写 # print(str6.startswith('my')) #startswith 判断前面 endswith 判断后面 # print(str6.startswith('My')) # print(str6.endswith('tank')) # #fomat 三种玩法 # str7 = 'my name in {},my age is{}' # str7=str7.format('tank',18) # print(str7) # # str7='my name in {1},my age is{2}' # str7=str7.format('tank',18,111) # print(str7) # # str7='my name in {name},my age is{age}' # str7=str7.format(name='tank',age=18) # print(str7) # ''' # # join 对列表中的数据按照某种标识拼接 拼接要为字符串类型 # name ='tank' # age='20' # print(':'.join([name,age])) # #replace # str8 ='old new' # str8=str8.replace('old','new') # print(str8) # #isdigit 判断字符串是否为数字 # ID =input('请输入') # print(ID) # print(ID.isdigit()) list1=['tank',18,'womale',3.0,9] print(list1[4]) print(list1[-2]) print(list1[1:5:2]) print(len(list1)) #追加 append() list1.append('sjkd') print(list1) #删除 pop()默认最后一个-1 print(list1.pop()) print(list1.pop(0)) print(list1) list1. #循环
标签:tank,name,python,list1,str7,day1,实训,print,my 来源: https://www.cnblogs.com/wangtianen/p/11006783.html