#coding: utf-8
x = "There are %d types of people." % 10 #定义x为一串数组变量
binary = "binary" #定义binary为字符串“binary”
do_not = "don't"
y = "Those who know %s and those tho %s." % (binary, do_not) #输出一句话,其中两个单词先被%s替代,然后申明这两个空缺分别为什么
print x #输出x和y
print y
print "I said: %r." % x #注意x中既有字符型也有数字型,于是用%r将其全部输出
print "I also said: '%s‘." % y
hilarious = False #将hilarious定义为一个判断结果
joke_evaluation = "Isn't that joke so funny?! %r" #这个变量很有意思,本身这个变量就有一个缺口,这个缺口不放东西就不能输出,类似一个“残缺变量”
print joke_evaluation % hilarious #现在输出这个变量,但注意后面必须要申明补这个缺口的是什么,否则无法输出,顺便知道python是一行一行跑的,前面没问题则会跑下去,直到有问题的第一行
w = "This is the left side of..."
e = "a string with a right side."
print w + e #这说明两个字符串是可以相加的,代表着连续输出
ex6.py 字符串和文本
最新推荐文章于 2023-03-12 21:30:29 发布