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

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.

thanks thats just what I needed!

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.