pythonベース構文のレビュー


データ分析pythonベース構文のレビュー
リスト#リスト#
# 1、     
list1 = ['  ',' ',33,'  ','  ','  ',['  178','  56']]
#        
print(list1[0])
#        
print(list1[3])
#         
print(list1[-1])
print(list1[6])
#          
print(list1[-1][-1])
print(list1[-1][1])
print(list1[6][-1])
print(list1[6][1])


# 2、     
#         
print(list1[-1])
#             
print(list1[-1][0])
#          
print(list1[-3])


# 3、    
list2 = ['  ','  ','  ','  ','  ','  ','  ','  ']
print(list2[2:6])  #     
print(list2[1:6:2])  #      2
print(list2[-3:])  #         
print(list2[:3])
print(list2[::])
print(list2[::2])  #  0         

# 4、       
list3 = [1,10,100,1000,10000]
list3.append(2)  # append           
list3
list3.extend([20,200,2000])  # extend              ,         
list3
list3.insert(2,11)  # insert           ,      ,      (       )
print(list3)
list3.insert(3,[11,22,33])
list3


# 5、       
list3.pop()  #            (  ),         ,           
print(list3)
list3.pop(2)
print(list3)
list3.remove([11,22,33])  # remove          ,             
list3
list3.clear()  #     


# 7、       --    
list4 = ['   ','  ','   ','  ','  ']
list4[0] = '  '
list4


# 8、         
list5 = [7,3,9,11,4,6,10,3,7,4,4,3,6,3]
print(list5.count(6))
print(list5.index(6))
#        
list5.reverse()
print(list5)
#   --           
list5.sort(reverse=True)
print(list5)

メタグループ
tup = ('a','d','z','a','d','c','a')
print(tup.count('a'))
print(tup.index('c'))

辞書
dict1 = {'  ':'  ','  ':33,'  ':' ','  ':{'  ':'  ','  ':'  '},'  ':['  ','  ','  ']}
dict1['  ']
dict1['  ']['  ']
dict1['  '][1]


# 1、       
dict1.setdefault('  ','  ')  # setdefault      ,          
dict1
dict1.update({'  ':'  '})  # update        
dict1


# 2、       
dict1.pop('  ')
dict1
dict1['  '].pop('  ')
dict1
dict1['  '].pop(1)
dict1
#            
dict1.popitem()
#     
dict1.clear()
dict1


# 3、       
dict1 = {'  ':'  ','  ':33,'  ':' ','  ':{'  ':'  ','  ':'  '},'  ':['  ','  ','  ']}
dict1.update({'  ':22})  # update         ,         
dict1
dict1['  '] = '  '
dict1
dict1['  '][1] = '  '
dict1
dict1['  ']['  '] = '  '
dict1


# 4、      
dict2 = {'  ':['       ','         ','     '],
         '  ':['     ·   ','   ','  ·    '],
         '  ':[9.1,9.2,9.2]}

dict2.get('  ')
dict2.keys()
dict2.values()
dict2.items()  #