简体   繁体   English

语法错误列表/字典

[英]Syntax Error list/dict

Python 3: someList = [0000, 1000, 0100]#, 1100, 0010, 1010, 0110, 1110, 0001, 1001, 0101, 1101, 0011, 1011, 0111, 1111] Python 3:someList = [0000,1000,0100]#,1100,0010,1010,0110,1110,0001,1001,0101,1101,0011,1011,0111,1111]

have a list which gives me a syntax error if I put more than 2 items in the list 有一个列表,如果我在列表中放入两个以上的项目,则会出现语法错误

someList = [0000, 1000] works but if I add anymore it keeps giving me an error someList = [0000,1000]有效,但是如果我再添加一次,它总是给我一个错误

Using the same list, I get a syntax error in Python 3 on your number "0100", not because it is the third item, but rather, due to the value itself. 使用相同的列表,在您的数字“ 0100”上收到Python 3的语法错误,不是因为它是第三项,而是由于值本身。 I also get a syntax error just doing 我也只是在做语法错误

someList = []
someList.append(0100)

So really it seems to be the value causing the problem. 因此,实际上似乎是造成问题的价值所在。 I'm not sure exactly what you are trying to do, but if you just want binary literals in a list, you can use something like this: 我不确定您到底想做什么,但是如果您只想在列表中使用二进制文字,则可以使用如下代码:

someList = [0b0000, 0b1000, 0b0100, 0b1100, 0b0010, 0b1010, 0b0110, 0b1110, 0b0001, 0b1001, 0b0101, 0b1101, 0b0011, 0b1011, 0b0111, 0b1111]

..where the "0b" prefix (that's zero b) represents a binary number. ..其中“ 0b”前缀(即零b)表示二进制数。

Interesting link on the different python versions and their handling of base literal values here: How do you express binary literals in Python? 有关不同python版本的有趣链接及其对基本文字值的处理, 请参见如何在Python中表达二进制文字?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM