关于Python中dictionary中关键字问题

yjgx007 2008-04-02 11:26:52
为什么list不能作为关键字,tuple可以呢?
这里涉及到immutable概念, 只有不可变的对象能够成为关键字,list是可变的.
...全文
70 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
ChumpKlutz 2008-04-02
  • 打赏
  • 举报
回复
list是可变对象所以不成作为key
RobotFramework常⽤关键字 常⽤关键字 虽然通过RIDE提供"填表"⼀样的写测试⽤例的⽅式。但它却⽀持强⼤的关键字功能,以及可以开发关键字的扩展能⼒。 Comment 注释功能,也可以使⽤python的"#" Comment 注释 注释 #注释 log 打印。类似于print log Hello World set variable 定义变量 ${a} set variable Hello World!!! log ${a} catenate 连接对象 ${a} catenate hello world log ${a} SEPARATOR 对多个连接进⾏分割(必须⼤写) ${a} catenate SEPARATOR=, hello world log ${a} create list 创建列表 ${a} create list a b c log ${a} 通过 通过@{}定义列表 定义列表 必须使⽤ log many 打印 @{a} create list a b c log many @{a} get time 获取当前时间 ${a} get time log ${a} sleep 设置休眠时间 ${a} get time sleep 5 ${a} get time ${a} get time run keyword if 通过该语句可以编写if分⽀语句 ${a} set variable 59 run keyword if ${a}>=90 log 优秀 ... ELSE IF a >= 60and{a}<90 log ⼀般 ... ELSE log 菜 :FOR 实现循环 :FOR ${i} IN RANGE 10 log ${i} 列表遍历 列表遍历 @{lista} create list a b c :FOR ${a} in @{lista} log ${a} Exit For Loop If 退出循环的判断语句 @{lista} create list a b c :FOR ${a} IN @{lista} exit for loop if '${a}'=='b' log ${a} Evaluate 执⾏python的⽅法 ${a} Evaluate random.randint(1000,9999) random log ${a} Import Library 导⼊标准和第三⽅模块或框架。⽐如调⽤unittest单元测试框架 Import Library unittest 导⼊外部py⽂件 Import Library c:/test.py ${sum} add 3 4 log ${sum} Import Library c:/test.py ${a} Evaluate int(4) ${b} Evaluate int(5) ${sum} add ${a} ${b} log ${sum} Take Screenshot 截取当前屏幕,Screenshot库为robot framework的标准类库,需⼿动加载 字典 字典 Collections库:该库为Robot Framework标准类库,它提供的关键字主要⽤于列表、索引、字典的处理。需要⼿动加载。 Create Dictionary 创建字典 ${dict} Create Dictionary sname Luffy age 19 Get Dictionary Items 获取字典的key和value " item"GetDictionaryItems"{dict} " " log " ${item} "" Get Dictionary Keys 获取字典的key ${keys} Get Dictionary keys ${dict} log ${keys} Get Dictionary Values 获取字典的value ${values} Get Dictionary Values ${dict} log ${values} Get From Dictionary 根据key获取对应的value ${a} Get From Dictionary ${dict} sname log ${a} Processing math: 100%

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧