递归火山软件开发平台

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 火山 源码 类库
查看: 1913|回复: 0
打印 上一主题 下一主题

[视窗] 为什么python不支持中文函数啊....

[复制链接]

5

主题

13

帖子

96

积分

注册会员

Rank: 2

积分
96
跳转到指定楼层
楼主
发表于 2022-1-7 17:11:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
import random
randomdict = {i : random.randint(50, 500) for i in range(1, 6)}
print(randomdict)               # {1: 79, 2: 425, 3: 145, 4: 220, 5: 223}

name = ["张三", "李四", "王五", "李六"]  # 保存名字列表
sign = ["白羊座", "双鱼座", "狮子座", "处女座"]  #保存星座列表
dict1 = {i : j for i, j in zip(name, sign)}    # 字典推导式
print(dict1)                    # {'张三': '白羊座', '李四': '双鱼座', '王五': '狮子座', '李六': '处女座'}

dict1 = {"a":10,"B":20,"C":True,"D":"hello world","e":"python教程"}
dict2 = {a:b for a,b in dict1.items() if a.isupper()}
print(dict2)
dict3 = {a.lower(): b for a, b in dict1.items()}
print(dict3)
dict4 = {a: b if a.isupper() else "error" for a, b in dict1.items()}
print(dict4)
def 字典操作(aa):
    aa = {a: b +100 if isinstance(b,int) else "error" for a, b in aa.items()}
    bb = {a:b for a,b in aa.items() if b!='error'}
    return bb
print(字典操作(dict1))


这里将"字典操作"函数名随便改个英文字母就能运行了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|递归火山软件开发平台 ( 鄂ICP备18029190号 )

GMT+8, 2024-6-18 04:57 , Processed in 0.076436 second(s), 17 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表