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

学习笔记-20150519

时间:2015-05-20 08:15:51      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

字符串的合并和占位符的使用
注意在%号前不能有引号。

技术分享

  1.  1 # -*- coding:utf-8 -*-
     2 my_name =中国
     3 my_age =35
     4 my_height =74
     5 my_weight =180
     6 my_teeth =White
     7 my_hair =Brown
     8 print("Let‘s talk about %s."% my_name)
     9 print("He‘s %d inch tall, %s"%(my_height, my_name))
    10 #test注意
    11 print("Let‘s add my height %d to my weight %d,and get the result: %d"%(my_height,my_weight,my_height+my_weight))

     

另一个例子:

  1.  1 x ="There are %d types of people"%10
     2 binary ="binary"
     3 do_not ="don‘t"
     4 y="Those who know %s and those who %s."%(binary,do_not)
     5 print x
     6 print y
     7 print"I said:%r"%x
     8 print"I also said: ‘%s‘."% y
     9 hilarious =False
    10 joke_evaluation ="Isn‘t that Joke so funny?! %r"
    11 print joke_evaluation %hilarious
    12 w="This is the left side of ..."
    13 e="a string with a right side."
    14 print w+e

     

运行结果:

There are 10 types of people
Those who know binary and those who don‘t.
I said:‘There are 10 types of people‘
I also said: ‘Those who know binary and those who don‘t.‘.
Isn‘t that Joke so funny?! False
This is the left side of ...a string with a right side.





附件列表

 

学习笔记-20150519

标签:

原文地址:http://www.cnblogs.com/dabiao/p/4516216.html

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