python字符类型

2022/3/9 22:14:57

本文主要是介绍python字符类型,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

# -*- coding:utf-8 -*-
# auther = 林深见鹿,海蓝见鲸


'''

dict = {"Bob":["class1"],"Alex":"class2","Gob":"class3","Joe":"class4"}
dict['jiao'] = "class5"
print(dict)
print(dict.keys())
print(dict.values())
print(dict.items())
print(dict["Bob"])

for k,v in dict.items():
    print(k,v)

for k in dict:
    print(k,dict[k])
for k in dict.keys():
    print(k)
print(len(dict))



'''

'''

import random
sum_number = []
count = 1


for i in range(1,301):
    sum_number.append(i)
print("总员工号:",sum_number)

for i in range(6):
    count += 1
    if count <=4:
        win1 = random.sample(sum_number, 30)
        for j in win1:
            # print(j)
            sum_number.remove(j)
        print("剩余未中奖人员",len(sum_number))
        print(f"第{count}次开奖")
        print(f"三等奖中奖名单:{win1}")
    elif 5 <= count <7:
        win2 = random.sample(sum_number, 10)
        for k in win2:
            # print(j)
            sum_number.remove(k)
        print("剩余未中奖人员",len(sum_number))
        print(f"第{count}次开奖")
        print(f"二等奖中奖名单:{win2}")

    elif count == 7:
        win3 = random.sample(sum_number, 1)
        for q in win3:
            # print(j)
            sum_number.remove(q)
        print("剩余未中奖人员",len(sum_number))
        print(f"第{count}次开奖")
        print(f"一等奖中奖名单:{win3}")

    else:
        exit("抽奖结束")


'''

'''

import random
import time
staff_number = []
for i in range(300):
    staff_number.append(f"员工{i}")
print(staff_number)
level = [30,6,3]
for i in range(3):
    # print(level[i])
    winpople = random.sample(staff_number,level[i])
    # print(i)
    for p in winpople:
        # print(p)
        staff_number.remove(p)
    print(f"抽中{3-i}等奖的人是:{winpople}")
    time.sleep(1)
    
'''

'''
all_user = [
    ["赵","北京市顺义区"],
    ["钱","北京市昌平区"],
    ["孙","北京市密云区"],
    ["李","山东省德州市"],
    ["周","河北省衡水市"],
    ["吴","天津市南开区"],
    ["郑","上海市长宁区"],
    ["王","河南省郑州市"],
    ["牛","内蒙古呼和浩特"]
]
new_list = {}
for i in all_user:
    print(i[1][:3])
    print(i)
    if i[1][:3] not in new_list:
        new_list[i[1][:3]] = [i]
        print(new_list[i[1][:3]])
        print([i])
        print(new_list.keys())
    else:
        new_list[i[1][:3]].append(i)

for k in new_list:
    print(k,end="\n")
    print(new_list[k],end="\n")

'''

'''
dict = [["Bob","class1"],["Alex","class2"],["Gob","class3"],["Joe","class4]"],["class1","class]"]]

# print(dict)

d2 = {}

for i in dict:
    # print(i)
    # print(i[1][:6])
    if i[1][:6] not in d2:
        d2[i[1][:6]] = [i]

    else:
        d2[i[1][:6]].append(i)

print(d2)
for k in d2:
    print(k,end='\n')
    print(d2[k],end='\n')

'''

'''
f = open(r"C:\\Users\\xckj-jiaoweinan\Desktop\\1.txt",mode="r+",encoding="utf-8")

data = f.read()
print(data)
f.write("jiao\n")
f.write("jiao1\n")
new = data.replace("jiao1","焦")
print(new)
f.write(new)
f.close()
countsum = data.count("jiao")
print(countsum)
f.seek(0)
f.truncate()

'''

'''
a = [1,2,3,4,5,6,7,8,9,0]
print(bool(True))
print(all(a))

'''

'''
all_name = dict(name="Bob", age="20", class_number="1班")
print(all_name)
print(dir())
print(locals())
# dir()打印当前程序全部变量名
# locals()打印当前程序全部变量名和变量值
a = list()
a.append("1")
print(a)
l = list(range(10))
print(l)


def count(x):
    return x ** 2


res = map(count, l)  # 并没有执行 (迭代器),方法只能定义一个参数,方法需要return
for i in res:  # 每循环一次,就把列表的元素给count函数执行
    print(i)

rex = max(l) #求最大值
rem = min(l) #求最小值
reum = sum(l) #求和
print(rex)
print(rem)
print(reum)


'''

'''
print(round(1.2331566,3))
a = ["1","2","3"]
b = ["a","b","c"]
print(zip(a,b))
# 两个列表每个元素配对,只一一对应,多出的元素不显示配对(py2显示为none)
for i in zip(a,b):
    print(i)
'''

 



这篇关于python字符类型的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程