python中拼接字符串的两种方法

第一种是format形式,第二种%百分号形式,举例如下:

str1 = "hell {},how old are you? I'm {}".format('lcx',10)
str2 = "hell %s,how old are you? I'm %s" %('liucx',11)
print(str1)
print(str2)

输出如下:

   hell lcx,how old are you? I'm 10
   hell liucx,how old are you? I'm 11



posted @ 2022-02-28 22:40  LCX测试小姐姐  阅读(304)  评论(0编辑  收藏  举报