• 南哥

python - Use % in Python String

Updated: Oct 14




brand = 'Apple Macbook Air M1'
exchangeRate = 0.154707

message = 'I just bought a new %s computer for %d USD and the exchange rate is %4.2f USD to 1 CN' %(brand, 1600, exchangeRate)

print (message)



%s is used to represent a string value

%d is used to represent a integer value

%f is used to represent a float value

P.S. I did buy an Apple Macbook Air M1


15 views0 comments

Recent Posts

See All