LearnPython3theHardWay__Excercise 6 Strings and Text

知识点了解字符串,初次接触str.format方法
之前的练习一直在写字符串(strings),可能你还不知道它们有什么用。现在我们加强练习来弄明白它们是干什么的。
首先解释一下:字符串是你想给某人看的信息,或者你想从程序里输出一些东西。只要放在单引号或双引号里通过 print 就能输出来。我们之前使用 f"blahblah{变量}" 把需要的变量放进去。
python还有另一个格式: .format(), 我们接下来的练习中会用到。

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

binary = "binary"   # 二进制
do_not = "don't"
y = f"Those who know {binary} and those who {do_not}."

print(x)
print(y)

print(f"I said: {x}")
print(f"I also said: '{y}'")

hilarious = False
joke_evaluation = "Isn't that joke so funny?! {}"

print(joke_evaluation.format(hilarious))
# 我们看到的更多的是下面的写法
# print("Isn't that joke so funny?! {}".format(hilarious))  

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

print(w + e)  # 将两句用 + 号连起来 

What you should see
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.

Stuey Drills

1、为每行添加注释
2、找出所有 字符串含字符串 的位置,总共有4处
3、你确定只有4处吗?我可能是骗你的
4、解释一下最后一行。 + 号的用法

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值