本文转载:https://xiaochuhe.blog.csdn.net/article/details/122512960
一、知识点11~15
#11.反斜杠与直接显示原始字符串
print("青鸟\n最美")
print(r"青鸟\n最美")
#12.类型的判断
'''
isalnum(字母加数字为真)
isalpha(全字母为真)
isdigit(全数字为真)
isnumeric(只包含数字字符为真)
'''
a = '1.5'
b = '1'
print (a.isalnum())
print (b.isdigit())
#13.函数必懂知识点
'''
#len(string)返回字符串长度
#lstrip()去掉左边的空格
#rstript()去掉字符串末尾的空格
#encode(usf-8) 默认为UTF-8
'''
#14.列表的使用,for与while的遍历
a = ["青鸟","世子","鱼幼微"]
for i in a:
print(i,end=",")
print ('\n---------------')
a = ["青鸟", "世子", "鱼幼微"]
length = len(a)
j =0
while j <length:
print(a[j])
j +=1
#15.数据的增加(append,extend,insert
name = ["A","B","C"]
zengjia = input("请输入:")
aa = ["1","2"]
name.append(zengjia) #将整个列表添加,包括列表的【】
name.extend(aa) #讲列表中的元素增加到另外一个里面
name.insert(1,"d") #在列表的1号位,插入数据d
print(name)
输出结果:
二、知识点16~20
#16.数据的删除——del,pop,remove
name = ["A","B","C"]
del name[1] #删除指定下标的对象
print (name)
name.pop() #删除数组组后的一位
#name.remove("B") #删除指定的对象,但是执行一次后失效
print(name)
#17.数据的修改
name = ["A","B","C"]
name[1]="D" #指定数据下表修改
print(name)
#18.数据的查(in / not in)
name = ["A","B","C"]
na= input("输入查找的对象:")
if na in name:
print("对象存在")
else:
print("不存在")
#19.数据的查找
#查找对象位置,不在范围内会报错,后面通过异常处理错误就行
a = ["a","b","c","d","e"]
b= [1,3,2,4]
print(a.index("d",0,4)) #数据的查找
#20.元素的操作
print(a.count("c"))
a.reverse()#元素反转输出
a.sort() #元素升序输出
print(a)
a.sort(reverse=True) #元素降序输出
print(a)
输出结果: