I'm trying to figure out how to use '%s'. I looked it up in the python docs but it never actually shows how to use it.

This is the line I'm working on right now just to figure it out. It is the first one of different variations where the location of the %s didn't give me an immediate syntax error and actually ran the code.

print('%sPlayer ', x %':') 

What I'm trying to do is get it to print out like this "Player x:" where x is an integer.

Recommended Answers

try

print('Player %s:' % x)
Jump to Post
print('Player %i:' % x) 
Jump to Post

All 5 Replies

try

print('Player %s:' % x)
print('Player %i:' % x) 

Both seem to work. So, if I understand this then, you put the first one where you want the value to appear in the string then the second one after the string followed by the value you want to be placed in the string? How would it work if you wanted to use more than one variable?

    print('Player %i: %s' % (x,'test')) 
Be a part of the DaniWeb community

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