>>> print(This seems like a fun idea!")
File "<stdin>", line 1
print(This seems like a fun idea!")
^
SyntaxError: invalid syntax
>>>
>>> print("This seems like a fun idea!)
File "<stdin>", line 1
print("This seems like a fun idea!)
^
SyntaxError: EOL while scanning string literal
>>>
>>> print(This seems like a fun idea!)
File "<stdin>", line 1
print(This seems like a fun idea!)
^
SyntaxError: invalid syntax
>>>
>>> 2++2
4
>>> 2--2
4
>>> 2+-2
0
>>> 2-+2
0
>>>01
File "<stdin>", line 1
01
^
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers
>>>
If one needs to display a leading zero, consider using print()
ie)
>>> print(0)
0
>>>
As Navone explains, Python 2 accepted leading zeros but it lead to errors such as
>>> 0000015
13
because it was converting numbers from octal (base 8) to (base 10). (Navone, 2001)
>>> 1 0
File "<stdin>", line 1
1 0
^
SyntaxError: invalid syntax
Python does not know what to the input isn't following syntax rules. (Downey, 2015)
>>>1+2+3+4+5
15
>>>
>>> 8--8
16
>>> 8----9
17
Each set of substraction operators turn into plus signs
>>>8+5*5
33
Python is reading this as 8+(5*5) even without the parantheses
Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tea Press. This book is licensed under Creative Commons Attribution-NonCommercial 3.0 Unported (CC BY-NC 3.0). Navone, Estefania. (2019, February 5). Leading Zeros in Python: A Hidden Mystery Revealed. Medium.com. Retrieved January 28, 2022, from https://medium.com/techmacademy/leading-zeros-in-python-a-hidden-mystery-revealed-ee3e3065634d