Little question about %

Sometimes I find something like this %s or similar %m in the code and I don’t know what it is.

import datetime
now =
print ("Current date and time : ")
print (now.strftime("%Y-%m-%d %H:%M:%S"))


color_list = [ "Red", "Green", "White", "Black" ]
print( " %s %s " % ( color_list[0], color_list[-1] ) )

do these code snippets containing % have their name, what is that? How we use that?

Hey @system2261074837!

These %s are used to insert the variable names after them (the ones in parentheses) into the string so you don’t have to do the whole "blah " + variable_name + " blah".

1 Like

but i can use any letter in % ? %s, %i, %z ? and only % stick to value?

Well, %s is used specifically for string variable values. If you want to use numbers, try %d.

1 Like

and % stuff have own name ?

I’m not sure what you mean… those are the only two letters to my knowledge that respond in the same way.

1 Like

I want to find it in the documentation. Thst’s why i ask for a name.

S string formatting I think is the correct term.

1 Like