• 欢迎访问我的个人博客网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站。
  • 如果您觉得本站对您有用,那么赶紧使用Ctrl+D收藏吧!
  • 相关内容持续完善中......

笨办法学python-习题6:字符串(string)和文

Python hubin 1年前 (2018-02-09) 282次浏览 0个评论 扫描二维码

练习:

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

习题:

1.在程序每一行的上面写一行注解

#字符串”There are 10 types of people.”赋值给变量x

x = “There are %d types of people.” % 10

#字符串”binary”赋值给变量binary

binary = “binary”

#字符串”don’t”赋值给变量do_not

do_not = “don’t”

#字符串”Those who know %s and those who %s.” %(binary,do_not)赋值给变量y

y = “Those who know %s and those who %s.” %(binary,do_not)

#打印变量x的值

print x

#打印变量y的值

print y

#打印”I said: %r.”%r引用变量x的值

print “I said: %r.” % x

#打印”I also said: ‘%s’.”%s引用变量y的值

print “I also said: ‘%s’.” % y

#布尔值False赋值给hilarious

hilarious = False

#字符串”Isn’t that joke so funny?! %r”赋值给变量joke_evaluation

joke_evaluation = “Isn’t that joke so funny?! %r”

#打印“Isn’t that joke so funny?! %r”%r是变量hilarious的值

print joke_evaluation % hilarious

#”This is the left side of…”赋值给变量w

w = “This is the left side of…”

#”a string with a right side.”赋值给变量e

e = “a string with a right side.”

#打印变量w+变量e

print w + e

2.找到“字符串包含字符串”的位置

y = “Those who know %s and those who %s.” %(binary,do_not)

print y

print “I said: %r.” % x

print “I also said: ‘%s’.” % y

print joke_evaluation % hilarious

3.print w + e 两个字符串或多个字符串可以用“+”连接


本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:笨办法学python-习题6:字符串(string)和文
喜欢 (0)
hubin
关于作者:
头像
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址