Sunteți pe pagina 1din 3

4/8/2017 Lists

In[1]: my_list=[1,2,3]

In[2]: my_list

Out[2]: [1,2,3]

In[3]: my_list=['string',23,1.2,'o']

In[4]: my_list

Out[4]: ['string',23,1.2,'o']

In[5]: len(my_list)

Out[5]: 4

In[6]: my_list=['one','two','three',4,5]

In[11]: my_list[0]

Out[11]: 'one'

In[12]: 1 my_list[1,:]


TypeErrorTraceback(mostrecentcalllast)
<ipythoninput1290a923547226>in<module>()
>1my_list[1,:]

TypeError:listindicesmustbeintegersorslices,nottuple

In[14]: my_list[1:]

Out[14]: ['two','three',4,5]

In[15]: my_list+['newitem']

Out[15]: ['one','two','three',4,5,'newitem']

In[16]: my_list=my_list+['newitem']

In[17]: my_list

Out[17]: ['one','two','three',4,5,'newitem']

http://localhost:8890/notebooks/Lists.ipynb 1/3
4/8/2017 Lists

In[18]: my_list*2

Out[18]: ['one',
'two',
'three',
4,
5,
'newitem',
'one',
'two',
'three',
4,
5,
'newitem']

In[19]: l=[1,2,3]

In[20]: l.append('appendme')

In[21]: l

Out[21]: [1,2,3,'appendme']

In[22]: l.append

Out[22]: <functionlist.append>

In[23]: l.pop()

Out[23]: 'appendme'

In[24]: l

Out[24]: [1,2,3]

In[25]: x=l.pop(0)

In[26]: x

Out[26]: 1

In[27]: l

Out[27]: [2,3]

In[28]: new_list=['a','e','x','b','c']

In[29]: new_list

Out[29]: ['a','e','x','b','c']

In[32]: new_list.reverse()

http://localhost:8890/notebooks/Lists.ipynb 2/3
4/8/2017 Lists

In[33]: new_list

Out[33]: ['c','b','x','e','a']

In[34]: new_list.sort()

In[35]: new_list

Out[35]: ['a','b','c','e','x']

In[36]: l_1=[1,2,3]
l_2=[4,5,6]

In[37]: l_3=[7,8,9]

In[38]: matrix=[l_1,l_2,l_3]

In[39]: matrix

Out[39]: [[1,2,3],[4,5,6],[7,8,9]]

In[43]: matrix[0]

Out[43]: [1,2,3]

In[44]: matrix[0][0]

Out[44]: 1

In[47]: matrix

Out[47]: [[1,2,3],[4,5,6],[7,8,9]]

In[48]: matrix[2][1]

Out[48]: 8

In[49]: first_col=[row[0]forrowinmatrix]

In[50]: first_col

Out[50]: [1,4,7]

In[]:

http://localhost:8890/notebooks/Lists.ipynb 3/3

S-ar putea să vă placă și