def day_of_week(date):
import datetime
return datetime.datetime.strftime(date, '%A')
date = datetime(2021,07,31)
print(day_of_week(date))
output:
File "", line 5
date = datetime(2021,07,31)
^
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers
>Solution :
The error here is that Python 3.0 and later doesn’t like integer literals that start with zero and consist only of digits — specifically, it’s complaining about the 07 integer literal.
The reason this is a problem is that using a 0 prefix on an integer literal used to, especially in the Unix tradition, indicate a number that’s supposed to be interpreted in octal (base-8) instead of decimal (base-10). For example, the Unix command chmod takes an octal value to set the flags for a file (e.g. chmod 0753 foo.txt). In Python you used to be able to do this same thing, but then it’s ambiguous how to interpret an integer literal starting with 0.
So to avoid the ambiguity, if you really want to specify an integer literal using octal notation, starting in Python 3 you must prefix the octal literal with 0o (that’s a zero and a lower-case letter o). Similarly, you can also specify other bases like 0x (hexadecimal, base-16), or 0b (binary, base-2).
>>> 58 == 0x3a == 0o72 == 0b111010
True
More information at https://www.python.org/dev/peps/pep-3127/