learn python the hard way (personal) -- Ex4-

Ex4:

注意浮点数的使用

Ex5:

1.变量名必须以字母开头;

 

2.如下所示变量在print时,注意加 f 和 {}

my_name = 'Lynn'
print(f"Let's talk about {my_name}.")

3.round() 返回浮点数的四舍五入值

Ex6:

变量赋值字符串的几种形式:

1.直接赋值为字符串

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

不同于Ex5中的print,上述只需要print(y)即可;

但如果加在其他中,也需f和{}

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

 

2.布尔值

 

hilarious = False
joke_evaluation = "Isn't that joke so funny?! {}"
print(joke_evaluation.format(hilarious))

注:这里hilarious赋为数值、字符串、布尔值都可以print出来,记住这种print形式。

 

Ex7:

print("Its fleece was white as {}.".format('snow'))

注意时常练习break it

 

Ex8: 

formatter = "{} {} {} {}"
print(formatter.format("one", "two", "three", "four"))

注意 .format() 这种形式

 

Ex9:

print("""
There's something going on here.
With the three double-quotes.
We'll be able to type as much as we like.
Even 4 lines if we want, or 5, or 6.
""")

print("""

"")

这种方式,中间可以插入无限行。

months = "Jan\nFen\nMar\nApr\nMay\nJun\nJul\nAug"

\n  为换行字符(new line character)

Ex10:

转义字符(escape sequences)

print("I am 6'2\" tall.") # escape double-quote inside string
print('I am 6\'2" tall.') # escape single-quote inside string

单双引号在字符串总应用时的转义。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值