一、列表
names=["aa","bb","cc","dd","ee"]
print(names)
print(names[0]+" "+names[1])
print(names[1:3])
print(names[0:3])
print(names[3])
print(names[-1])
print(names[-2])
print(names[-3:-1])
print(names[-1:-3])
print(names[-2:])
print(names[:3])
print(names.index("ee"))
print(names.count("cc"))
names.reverse()
print(names)
print(names[0].title())
print()
names[0]="aaaaaaaaa"
print(names[0])
names.append("ff")
print(names)
names.insert(0,"000000")
print(names)
输出结果
names.clear()
print(names)
[‘aa‘, ‘bb‘, ‘cc‘, ‘dd‘, ‘ee‘]
aa bb
[‘bb‘, ‘cc‘]
[‘aa‘, ‘bb‘, ‘cc‘]
dd
ee
dd
[‘cc‘, ‘dd‘]
[]
[‘dd‘, ‘ee‘]
[‘aa‘, ‘bb‘, ‘cc‘]
4
1
[‘ee‘, ‘dd‘, ‘cc‘, ‘bb‘, ‘aa‘]
Ee
aaaaaaaaa
[‘aaaaaaaaa‘, ‘dd‘, ‘cc‘, ‘bb‘, ‘aa‘, ‘ff‘]
[‘000000‘, ‘aaaaaaaaa‘, ‘dd‘, ‘cc‘, ‘bb‘, ‘aa‘, ‘ff‘]
[]
二、字典
alian_0={
‘color‘:‘green‘,
‘points‘:‘5‘
}
print(alian_0[‘color‘])
print(alian_0.get(‘color‘))
三、numpy
import numpy as np
array1=np.array([1,2,3])
print(array1)
print(array1.shape)
print(type(array1))
print(array1+array1)
print(array1*array1)
print(array1.dtype)
print(array1.ndim)
print(array1.size)
print(array1.transpose())
print(array1.T)
[1 2 3]
(3,)
<class ‘numpy.ndarray‘>
[2 4 6]
[1 4 9]
int32
1
3
[1 2 3]
[1 2 3]
array2=np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]])
print(array2)
print(array2.shape)
print(type(array2))
print(array2+array2)
print(array2*array2)
print(array2.dtype)
print(array2.ndim)
print(array2.size)
print(array2.transpose())
print(array2.T)
[[ 1 2 3 4]
[ 5 6 7 8]
[ 9 10 11 12]]
(3, 4)
<class ‘numpy.ndarray‘>
[[ 2 4 6 8]
[10 12 14 16]
[18 20 22 24]]
[[ 1 4 9 16]
[ 25 36 49 64]
[ 81 100 121 144]]
int32
2
12
[[ 1 5 9]
[ 2 6 10]
[ 3 7 11]
[ 4 8 12]]
[[ 1 5 9]
[ 2 6 10]
[ 3 7 11]
[ 4 8 12]]
四、panadas
原文地址:https://blog.51cto.com/doublelinux/2473239
时间: 2024-10-27 00:06:52