0

can someone show me the syntax for inserting Number literals and strings into python strings like the print statement for example(i.e print("string %s"),(SumNum)) .. I have forgotten. and could someone explain the difference between syntax and semantics to me , i have forgotten that also XD

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by ret801
0

Semantics is what you say; syntax is how you say it.

You can insert numbers and strings into other strings for later output in a variety of ways. Generally, you will use the format mini-language and the modulus operator (%). For very simple cases it is very easy. For instance

anint = 12
afloat = 12.3
astring = 'twelve'
formattedstring = "%d, %4.2f, %10s."%(anint,afloat,astring)
print(formattedstring)

I threw in some field size specifications just to show an example of them.

-1

just like c++ almost ok.. I wasnt sure if python uses the "modulous /type" syntax! thanks!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.