码迷,mamicode.com
首页 > 其他好文 > 详细

40、常用字符串格式化有哪几种?

时间:2018-06-22 22:47:46      阅读:880      评论:0      收藏:0      [点我收藏+]

标签:format   字典   IV   字符串   color   fir   nbsp   优点   str   

Python的字符串格式化常用的有三种!

  第一种最方便的

  缺点:需一个个的格式化

print(hello %s and %s%(df,another df))

 

  第二种最好用的

  优点:不需要一个个的格式化,可以利用字典的方式,缩短时间

print(hello %(first)s and %(second)s%{first:df , second:another df})

  第三种最先进的

    优点:可读性强

print(hello {first} and {second}.format(first=df,second=another df))

 

40、常用字符串格式化有哪几种?

标签:format   字典   IV   字符串   color   fir   nbsp   优点   str   

原文地址:https://www.cnblogs.com/zhuifeng-mayi/p/9215546.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!