加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

Python – 列表中冒号的语法错误

发布时间:2020-12-20 11:30:40 所属栏目:Python 来源:网络整理
导读:我一直在尝试创建一个简单的字典来定义用户输入的单词.在定义字典及其单词后,我正在尝试打印输入单词的定义.出于某种原因,当我尝试运行此程序时,列表中的冒号出现语法错误.我不知道如何解决这个问题,我知道有更简单的方法可以做到这一点,但我正在尝试使用列
我一直在尝试创建一个简单的字典来定义用户输入的单词.在定义字典及其单词后,我正在尝试打印输入单词的定义.出于某种原因,当我尝试运行此程序时,列表中的冒号出现语法错误.我不知道如何解决这个问题,我知道有更简单的方法可以做到这一点,但我正在尝试使用列表.
?这是迄今为止的代码:

字典

dic1 = [
    'bug':'A broken piece of code that causes a program to stop functioning'
    'string':'A piece of text'
    'integer':'A whole number'
    'float':'A decimal number'
    'function':'A block of organized and clean code that performs a task/action'
    'syntax':'A set of rules that says how a program will be coded'      
    ]

q = input("What coding related word do you want defined?")
if q in dic1:
    print(dic1[q])

解决方法

你在dict的每个条目末尾都忘了一个逗号. Dicts使用花括号“{…}”

dic1 = {
    'bug':'A broken piece of code that causes a program to stop functioning','string':'A piece of text','integer':'A whole number','float':'A decimal number','function':'A block of organized and clean code that performs a task/action','syntax':'A set of rules that says how a program will be coded',}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读