《笨辦法學python》加分習題6——我的答案
阿新 • • 發佈:2019-02-02
新手上路,請老司機多多指教。
文中練習:
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、
# -- coding: utf-8 --
#這裡有10種類型的人
x = "There are %d types of people." % 10
#命名
binary = "binary"
do_not = "don't"
#這些人知道bianry,而著一些人不知道bianry
y = "Those who know %s and those who %s." % (binary, do_not)
#列印x和y
print x
print y
#我說x這段話
print "I said: %r." % x
#還是我說y這段話
print "I also said: '%s'." % y
#定義這個變數為False(bool型(題外話,今天才知道51沒有bool型別))
hilarious = False
#一個joke
joke_evaluation = "Isn't that joke so funny?! %r"
#列印joke 這個用法還是蠻好玩的,居然可以這樣用
print joke_evaluation % hilarious
#就w一段話,e一段話
w = "This is the left side of..."
e = "a string with a right side."
#兩段話合起來
print w + e
2、
y = "Those who know %s and those who %s." % (binary, do_not)
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
一個疑問,我回去檢查輸出的時候發現False是直接輸出False而不是我想的bool型輸出0。以上4處是字串內包含了字串。
3、
我只找到4處。
4、
相當於print第一個後再print第二個吧。python這點真舒服,感覺就是按自然語言梳理的,很舒服。