I add colon and semicolon after print but interpreter is not throwing error.
please run with python3.8.x(edit)
x=5
print:(x)
print;(x)
The interpreter thinks the colon is a type annotation. Which is why it raises SyntaxError
in earlier versions of Python, but is valid syntax in Python 3.6+.
In later versions of Python this is valid
a: int
As is this
import sys
def exclaim(string):
sys.stdout.write(f"{string}!")
print = exclaim
print("Hello")
I.e. You can annotate the type of a variable. And you can reassign print
.
So when you do print:(x)
the interpreter just thinks you're annotating print
to be of "type" 5
.
Semi-colons are valid Python, and are used to put two separate statements on the same line. They're just considered to by "unpythonic". You do see them used sometimes to do things like import pdb; pdb.set_trace()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With