SyntaxError invalid token

后端 未结 4 725
攒了一身酷
攒了一身酷 2020-12-05 09:16

I have a problem when I try to assign a value to a variable. The problem shows up when I try to put a date as a tuple or a list in this order: year, month, day.

4条回答
  •  渐次进展
    2020-12-05 10:01

    The problem is the 0 before the 4. If you want to store that kind of infos, try using strings.

    a = (2016,04,03) --> Error
    a = (2016,4,3) --> No Error
    a = ("2016","04","03") --> No Error
    a = "2016-04-03" --> you could retrieve Year, Month and Day by splitting this string
    

    In Python 2.x 04 is interpreted as an octal number. In Python 3 octal numbers are written in form 0o4 as written here : http://docs.python.org/3.0/whatsnew/3.0.html#integers

提交回复
热议问题