【无标题】

Python学习日志(2022-7-11):

学习内容:

1.元组

>>> a,b,c,d="life"
>>> a
'l'
>>> b
'i'
>>> c
'f'
>>> d
'e'
>>> a,b,c,d=(1,2,3,4)//解包
>>> a
1
>>> b
2
>>> c
3
>>> d
4
>>> 

2.字符串

>>> "在吗,我在你家楼下,快点下来".replace("在吗","想你")//字符串里有46个函数,可以勤加使用
'想你,我在你家楼下,快点下来'
>>> table = str.maketrans("ABCDEFG","1234567")
>>>> "HELLO,BABY".translate(table)
'H5LLO,212Y'

>>> w="123123321321"
>>> w.strip("321")
''
>>> w="123123321321"
>>> w.strip("3")//只能去除开头和结尾,按字符依次剔除,而不是整个字符串剔除
'123123321321'

>>> "www.google.com".partition(".")//分割
('www', '.', 'google.com')
>>> "www.google.com".split(".")
['www', 'google', 'com']
>>> "www.google.com".rsplit(".",1)
['www.google', 'com']

>>> ".".join("www","google","com")
Traceback (most recent call last):
  File "<pyshell#45>", line 1, in <module>
    ".".join("www","google","com")
TypeError: join() takes exactly one argument (3 given)
>>> ".".join(["www","google","com"])//join括号里必须是一个序列
'www.google.com'

>>> "1+2={},2²={},3*4={}".format("3","4","12")
'1+2=3,2²=4,3*4=12'
>>> "1+2={0},2²={1},2*={1}".format("3","4")
'1+2=3,2²=4,2*=4'
>>> "1+2={0},2²={answer},2*={answer}".format("3",answer="4")
'1+2=3,2²=4,2*=4'

>>> "{:,}".format(1234)
'1,234'
>>> "{:_}".format(1234)
'1_234'
>>> "{:,}".format(123456789)
'123,456,789'
>>> "{:.2f}".format(1.23456789)
'1.23'
>>> "{:.2}".format("123456789")
'12'

>>> "{:b}".format(80)
'1010000'
>>> "{:o}".format(80)
'120'
>>> "{:x}".format(80)
'50'
>>> "{:d}".format(80)
'80'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值