“笨办法”学Python3,Zed A. Shaw, 习题6

代码

types_of_people = 10
x2 = "There are {} types of people."
x1 = f"There are {types_of_people} types of people."

binary = "binary"
do_not = "don't"
y2 = "Those who know {} and those who {}."
y1 = f"Those who know {binary} and those who {do_not}."

if ( x1 is x2.format(types_of_people)):
    print("0 - yes")
else:
    print("0 - no")
if ( y1 == y2.format(binary,"don't")):
    print("0 - yes")
else:
    print("0 - no")

print("1 - " , x1)
print("2 - " , x2.format(types_of_people))
print("3 - " , y1)
print("4 - " , y2.format(binary,do_not))

print("5 - " , f"I said: {x1}")
print("6 - " , f"I said: {x2.format(types_of_people)}")
print("7 - " , f"I also said: '{y1}'")
print("8 - " , f"I also said: '{y2.format(binary,do_not)}'")

hilarious = "False"
joke_evaluation1 = "Isn't that joke so funny?!{}"
joke_evaluation2 = f"Isn't that joke so funny?!{hilarious}"

print("9 - " , joke_evaluation1.format(hilarious))
print("10 - " , joke_evaluation2)

w = "This is the left side of ..."
e = "a string with a right side."

print(w + e)

遇到问题

好几次把if 和 print,错输入成“If”和“Print”,结果一直提示错误。

学到的

1、如代码所示,a.format(b) == a=f"{b}"(看习题7的“学到的”,这里好像有点不对);
2、print()内的字符串使用“+”连接;
3、小括号“()”内可以使用字符串和值,而大括号“{}”内只能用值。例:y1是y1 = f"Those who know {binary} and those who {do_not}."而y2用法为y2.format(binary,“don’t”))。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值