AprilJoy/blog

python基础一

Opened this issue · 0 comments

字符串操作

 d="hello world"
 d.split(' ')
 d=['helo', 'oop']
 #连接
 ' '.join(d)
 e="hello world"
 e.upper()

数组操作

b_list = [3,4,5,2,1]
c_tuple = (2,3,4)
b_list = [3,4,5,2,1]
min(b_list)
sorted(b_list)
sum(b_list)
sum(c_tuple)
#排序
sorted(c_tuple)
type(c_tuple)
dog = ['Freddie', 9, True, 1.1, 2001, ['bone', 'little ball']]
dog.append(4)
dog
dog.remove(2001)
dog.count('Freddie')

字典操作

dog_dict = {'name': 'Freddie',
'age': 9,
'is_vaccinated': True,
'height': 1.1,
'birth_year': 2001,
'belongings': ['bone', 'little ball']}
dog_dict.keys()
dog_dict.values()
dog_dict['name'] = 'sss'