Day 4--Python--リストの添削、メタグループ、range

5000 ワード

#  .  
# ,
# []
# [start,end,step]
### ( )
# 1.
# appent(), insert(), extend()
##append() ,
# lst = []
# lst.append(' ') #
# lst.append(' ')
# lst.append(' ')
# print(lst)

##insert() ,
# lst = [' ', ' ',' ',' ']
# lst.insert(2,' ') # , #
# print(lst)

##extend() ,
# lst = [' ', ' ', ' ', ' ']
# lst.extend([' ',' ',' '])
# lst.extend(' ')
# print(lst)

   lst = [' ', ' ', ' ', ' ']
   lst.extend([1, 2, 3]) 
   print(lst) # [' ', ' ', ' ', ' ', 1, 2, 3]   


# 2. pop, remove, clear, del

##pop
# lst = [' ',' ',' ',' ']
# lst.pop()
# print(lst)
   lst.pop(index)

# lst = [' ',' ',' ',' ']
# s1 = lst.pop()
# print(s1)
# s2 = lst.pop()
# print(s2)
# print(lst)

#
#
# [' ', ' ']

##remove
# lst = [' ',' ',' ',' ']
# lst.remove(' ')
# lst.remove(' ')
# print(lst)

##clear
#lst = [' ',' ',' ',' ',' ']
# lst.clear() #
# print(lst)

##del
# lst = [' ',' ',' ',' ',' ',' ']
# del lst[2]
# del lst[0:3]
# del lst[::2]
# print(lst)


#
# 3.
# lst = [' ',' ',' ',' ',' ',' ']
# lst[2] = 'aaa'
# lst[-2] = 'sss'
# lst[1:3] = ['ddd'] # [1:3] , 1 'ddd' # [] , 1 lst = 'ddd' [' ', 'd', 'd', 'd', ' ', ' ', ' ']
# lst[1:5:2] = ['dd','dss'] # 1, , [],
#
# 4.
# for el in list: #element
# el
# 5.
# lst.count(' ')
# lst.sort() #
# lst.sort(reverse=True) # ,
# lst.reverse() #
# print(len(lst)) #len , ,
#
# print(lst)

# ------------------------------------------------
#
# lst = [' ',' ',' ', False, True, 500000000,3.14, [' ', [42, ' '],' ',' ']]
#
#print(lst[3]) #False
#print(lst[-4]) #True
#print(lst[0][1:3])

# [start, end, step]
#print(lst[1:3])
#print(lst[1:5:2])
#


#

# lst = [" ", " ", " ", " ", [" ", [" ", "alex", " "]," ", " ", " ", " "]]
#
# lst[4][1][1] = lst[4][1][1].capitalize()
# print(lst)
# alex



# . tuple
# , () , ,
#
# ()
# , (1,) tuple (1) int
# tuple() tu = tuple() #
# lst = list() # []
tuple   : count  , index  , len  , __iter__  , __init__ #   



# , ,
#
# tu = ("iphone", "nokia", " ", "Lenovo", "HTC", "Honor")
# print(tu[-1])
# print(tu[1:3])
# print(tu[1:5:2])
# ,
# tu = (1, 2, 5, [" ", " ", " ", " ", " "])
# tu[3].append(" ")
# print(tu)
#

# range()
# range(100) 0-99
# range(start, end) start end
# range(start, end, step)
#
# range
# for i in range(len(list)):
# list[i]
#-------------------------------------------------------------
# tu = (" ", " ", " ", " ", " ")
#
# for el in tu: # element
# print(el)


転載先:https://www.cnblogs.com/surasun/p/9599578.html