top of page
  • tcf

python - Use % in Python String

Updated: Oct 14, 2022




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


18 views0 comments

Recent Posts

See All
bottom of page