According to python 3 document, the string formating "%%" means "a perncet sign".
Following code is an example:
"%g%%" % 10.34 == "10.34%"
I am not sure what does this "%g" mean here, I suspect it should have the same meaning as "%g" in string formating, which is "Shorter one among %f or %e". and "%f" or "%e" means "floating point real number" or "Exponential notaion, lowercase'e'". Example of them are:
"%f" % 10.34 == '10.34000'
or
"%e" % 1000 == '1.000000e+03'
Based on this understanding, I tried follwoing code. I treid to formatting x first, and then directly use formating string "%%", but it does not work.
x = '%g' % 10.34
print(isinstance(x, float)) #this returns false
"%%" % x == "10.34%" # this returns error
I then tried this:
x = float(10.34)
print(isinstance(x, float)) #this returns true
"%%" % x == "10.34%" # this returns error as well
I even tried this:
x = "10.34000"
"%%" % x == "10.34%" # this returns error as well
Anyone know what is going on here with "%%". What its mean, do we have to use "%g%%" together with "%%" in any circumstance?
This is solved, the question comes from the misleading of the book. I made comments here: