python-内部函数总结
作者:互联网
'''1.enumerate 索引
举例:str="欢迎光临" 输出迎和对应的索引'''
# str="欢迎光临"
# for a,b in enumerate(str):
# if a==1 and b=="迎":
# print(a,b)
'''先循环for in的同时定义变量a和b,需要语法 if a== and b== " \
(a指索引,b指索引想要的目标)然后打印a和b。'''
'''2.range 获取一定的范围
举例:获取3-6的范围'''
# list=[a for a in range(3,6)]
# print(list)
'''使用列表推导式,需要循环3-6的范围,但不包括结尾6'''
'''3.zip 合并
举例:把list1和list2合并再一起'''
# list1=["a","b","c","d"]
# list2=[1,2,3,4]
# list3=zip(list1,list2)
# print(list(list3))
'''4.replace 替换
举例 把hello world 替换成 hi world'''
# str="hello world"
# print(str.replace("hello","hi"))
'''5.type 查询数据类型
举例 查询字符串str中的数据类型'''
# str=input("how are u?\n")
# print(type(str))
'''6.dir 查看对象可以用那些调用方法
举例 '''
# str="hello"
# print(dir(str))
'''7.index 查看字符串中某个目标在第几位
举例 查看字符串“asdfdfgh”中d在第几位'''
# str=("asdfdfgh")
# print(str.index("d"))
'''7.1 index 查看列表的索引
举例 查看列表go的索引'''
# list=["java","python","go","c+"]
# print(list.index("go"))
'''8.count 查看字符串的个数
举例 查看字符串hello world中l的个数'''
# str=("hello world")
# print(str.count("l"))
'''8.1 count 查看列表中某个目标出现的次数
举例 统计f出现的次数'''
# list=["hi","go","he","hi"]
# print(list.count("hi"))
'''9.find 查看并输出字符串的索引
举例 查看字串”python“中o的索引'''
# str=("python")
# print(str.find("o"))
'''10.append 增加
举例:给列表增加asd'''
# list=["a","df","agf"]
# list.append("asd")
# print(list)
'''11.insert 指定增加
举例 在列表go前面增加c+'''
# list=["java","python","go"]
# list.insert(2,"c+")
# print(list)
'''12.pop 删除
# 举例 默认删除列表'''
# list=["go","python","java"]
# list.pop()
# print(list)
'''13.remove 指定删除
举例;指定删除c+'''
# list=["go","java","c+","hgj"]
# list.remove("c+")
# print(list)
'''14.extend 追加
举例 追加list2到list1'''
# list=["sd","sds","tgrf"]
# list2=["fdd","fd","gfd"]
# list.extend(list2)
# print(list)
'''15.reverse 反转排序
举例:反转[23,54,65,93,76,42,70,83]'''
# list=[23,54,65,93,76,42,70,83]
# list.reverse()
# print(list)
'''16.sort 排序
举例 排序并反转[23,54,65,93,76,42,70,83]'''
# list=[23,54,65,93,76,42,70,83]
# list.sort(reverse=True)
# print(list)
'''17.max,min,sum,len 最大 最小 平均值
举例如下'''
# asd=[("a","90"),("b","30"),("c","88"),("d","100")]
# score=[]
# for a in asd:
# score.append(int(a[1]))
# print("最大",max(score))
# print("最小",min(score))
# print("平均",sum(score)/len(score))
# score.sort()
# print(score)
'''18.updata 字典追加
举例 把dict2追加到dict1中'''
# dict1={"name":"yvonne","age":18}
# dict2={"gender":"boy"}
# dict1.update(dict2)
# print(dict1)
'''19.ord,chr 字母转数字,数字转字母
举例'''
print(chr(10))
print(ord("f"))
标签:总结,函数,python,list,go,举例,str,print,score 来源: https://www.cnblogs.com/yvonnej/p/16383434.html