Python基础 之 格式化字符

1. 比较简单容易理解的字符串格式化

>>> print("%d%% people like sleeping." %90)
90% people like sleeping.

2. 比较好用的字典类型:字符串格式化

>>> print('customerA: %(first)s and customerB: %(second)s' % {'first': 'Jack', 'second': 'Kate'})
customerA: Jack and customerB: Kate

3. 比较高级的字符串格式化方法format

>>> print('{name} is {age} years old.'.format(name='Kate', age='20') )
Kate is 20 years old.

>>> print('{0} is {1} years old.'.format('Kate', 20) )
Kate is 20 years old.

相关文章:

  • 2021-08-16
  • 2022-01-16
  • 2022-12-23
  • 2021-06-06
  • 2021-04-13
  • 2022-12-23
  • 2022-12-23
  • 2021-06-21
猜你喜欢
  • 2021-07-15
  • 2022-12-23
  • 2022-12-23
  • 2021-07-06
  • 2021-10-25
  • 2022-02-18
相关资源
相似解决方案