1 Star 0 Fork 0

神神的棍子/python_test_obj

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
B_list_dict.py 2.64 KB
Copy Edit Raw Blame History
神神的棍子 authored 2019-12-31 09:17 . 1
# 序列切片
str1="C语言中文网"
#取索引区间为[0,2]之间(不包括索引2处的字符)的字符串
print(str1[:2])
#隔 1 个字符取一个字符,区间是整个字符串
print(str1[::2])
#取整个字符串,此时 [] 中只需一个冒号即可
print(str1[:])
# 序列相加
str1="c.biancheng.net"
print("C语言"+"中文网:"+str1)
# 序列相乘
str1="C语言中文网"
print(str1*3)
#列表的创建用 [],后续讲解列表时会详细介绍
list1 = [None]*5
print(list1)
str1="c.biancheng.net"
print('c'in str1)
print('c' not in str1)
# 和序列相关的内置函数
str1="c.biancheng.net"
#找出最大的字符
print(max(str1))
#找出最小的字符
print(min(str1))
#对字符串中的元素进行排序
print(sorted(str1))
print(len(str1))
ks = list(str1)
print(ks)
print("-------")
strs = str(ks);
print(type(strs))
sums = [15,12,10,45,52]
print(sum(sums))
print(sorted(sums))
print(reversed(sums))
# 列表
print(type([]))
tp = (1,2,3)
print(type(tp))
print(list(tp))
print(type(range(1,20)))
# 操作
p1 = list()
print(p1)
p1.append("1")
print(p1)
p1.append([1,2,3])
print(p1)
p1.extend([1,2,3])
print(p1)
p1.extend((1,2,3))
print(p1)
p1.insert(3 , "12222" )
del p1[0]
print(p1)
p1.remove("12222")
print(p1)
print("count" + str(p1.count(2)))
print(p1.index(2,2))
p1.pop()
print(p1)
p1.pop(0)
print(p1)
p1.clear()
print(p1)
p2 = [3,7,2,1,10]
p2.sort()
p2.sort(reverse=True)
# p2 = sorted(p2)
# print(p2)
# p2.reverse()
print(p2)
tuple1 = tuple(p2)
print(tuple1)
print(type(tuple1))
# dict
d1 = {"name" : "李" , "age" : 18}
print(d1)
print(type(d1))
print(d1["name"]);
d2 = dict.fromkeys(p2);
print(d2)
d3 = dict(name="哈哈" , age=20)
print(d3)
o1 = [[10,5]]
print(dict(o1))
print(d3.get("name"))
a = {'数学': 95, '语文': 89, '英语': 90}
print(a.keys())
print(a.values())
print(a.items())
a = {'数学': 95, '语文': 89, '英语': 90}
for k in a.keys():
print(k,end=' ')
print("\n---------------")
for v in a.values():
print(v,end=' ')
print("\n---------------")
for k,v in a.items():
print("key:",k," value:",v)
x1 = {"a" : 1 , "b" : 2 , "c" : [1,2,3]}
x2 = x1.copy()
print(x2)
x2["c"].remove(3)
print(x1)
a.update({'数学': 100})
print(a)
print(a.pop("数学"))
print(a)
k,v = a.popitem()
print(":::" + k + "..." + str(v))
print(a)
print(a.setdefault("历史",99))
print(a)
# Set集合
s = {1,2,3,4,5,6,6,6,6}
print(s)
print(s)
print(s)
print(s)
print(s)
print(s)
print(type(s))
s1 = set(["a","b","c"])
print(s1)
print(type(s1))
for ss in s1:
print(ss , end=',')
s1.add("d")
print(s1)
s1.remove("d")
s1.discard("d")
s2 = {"c","d","e"}
print("&" , s1 | s2)
print("|" , s1 | s2)
print("-" , s1 - s2)
print("^" , s1 ^ s2)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/layga/python_test_obj.git
git@gitee.com:layga/python_test_obj.git
layga
python_test_obj
python_test_obj
master

Search

0d507c66 1850385 C8b1a773 1850385