106-Python中常用占位符类型
Python中常用占位符类型
'The first letter of Python is %c' % 'P'
# 'The first letter of Python is P'
'Welcome to the world of %s!' % 'Python'
# 'Welcome to the world of Python!'
'Python has %i letters.' % len('Python')
# 'Python has 6 letters.'
number = 1.8888
print("Rounding %.4f to 2 decimal places is %.2f" % (number, number))
# Rounding 1.8888 to 2 decimal places is 1.89
number = 12
print("%i in octal is %o" % (number, number))
# 12 in octal is 14
number = 12000
print("%i is %.2e" % (number, number))
# 12000 is 1.20e+04