笨方法学python 习题6

字符串和文本

代码如下:

type_of_people = 10
x = f'There are {type_of_people} type_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}' ''')

hilarous = False
joke_evalution = '''Isn't that joke so funny?! {}'''

print(joke_evalution.format(hilarous))

w = 'That is the left side of ...'
e = 'a string with a right side.'

print(w + e)

输出:

There are 10 type_of_people
Those who know binary and those who don't
I said:There are 10 type_of_people
I also said:'Those who know binary and those who don't' 
Isn't that joke so funny?! False
That is the left side of ...a string with a right side.

巩固练习

  1. 把一个字符串放进另一个字符串:
x = f'There are {type_of_people} type_of_people'
y = f'Those who know {binary} and those who {do_not}'
print(joke_evalution.format(hilarous))
print(w + e)
  1. w和e用+连起来为什么生成更长的字符串?因为+ 左右两端必须是字符串,表示字符串的连接
  2. 单引号和双引号贼容易报错,得试试看…

Tips:

  1. 字符串是你想要展示给别人的或者想要从程序里导出的一小段字符,通常以(‘’‘’)或者(‘’)识别字符串
  2. 变量是“名字=值”
  3. 使用.format()语法的格式化方式
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值