As you know, the ; symbol is used to separate lines like this:
print "Hai"; print "Bai"
From what I've heard, this goes against formatting standards for python. So, if this goes against formatting standards, why was it implemented? How is it used properly?
";" are used in cases, you have no other choice. E.g. when calling Python from command line and willing to execute those two statements.
$ python -c "print 'Hai'; print 'Bai'"
Hai
Bai
Or more complex cases:
$ python -c 'a=1; b=2; print "a + b = {a} + {b} = {res}".format(a=a, b=b, res=a+b)'
a + b = 1 + 2 = 3
note: Do not take my "no other choice" literally, you will find nice alternatives to some cases in comments.
To extend on Jan Vlcinsky's answer, if you're trying to quickly determine the efficiency of something, timeit comes in handy. For example, (from the docs):
python -m timeit -s 'text = "sample string"; char = "g"' 'char in text'
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