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("在吗","想你")
'想你,我在你家楼下,快点下来'
>>> 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"])
'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'