print & string formatting

Abdur-Rahmaan Janhangeer arj.python at gmail.com
Sun Jul 22 00:53:32 EDT 2018


*Folks,I get a lot confused while using print functions in Python.For
example, I get the same results for the following code:str = "one two
three"print strprint "%s" %(str)So, what is the need to use the second
method which I see being used in many programs I am referring to*

well
1) that is more convenient than concatenation ""+x+""
2) no need for casting
x = 64
"%d" %(x)
3) the .format() or f'' makes it simpler and reflects the real spirit of py
"{}".format(y) # no need to specify s or d etc


-- 
Abdur-Rahmaan Janhangeer
https://github.com/abdur-rahmaanj
Mauritius



More information about the Python-list mailing list