Day03 third base three Python

#_Author_: yaoyaoba 
#_Date_: 2019/11/26

. # A list of add / delete / change / check

# append inserted by an end of the list
# s = [1,2,3, 'fjdkaj ', 'fdsaeddd', 1234, 'ffdsaecc']
# s.append ( 'xianren')
# Print (S)

# # a method (defective)
# HR = []
# the while. 1:
# hr.append (iNPUT ( "Please input the input person (exit, press 'Q'): "))
# IF 'Q' in HR:
# Print (HR)
# BREAK

# # method 2 (perfect)
# HR = []
# the while. 1:
# username = INPUT ( "Please enter the person you want to record (exit press 'Q'):")
# if username.strip().upper() == 'Q':
BREAK #
# the else:
# hr.append (username)
# Print (HR)
# -------------------------------- ------------

# insert by inserting the index to
# S = [l, 2,3, 'fjdkaj', 'fdsaeddd', 1234, 'ffdsaecc']
# s.insert (. 4, 'I Transfer Students') = # insertion position index location, the original data is shifted one position index
# Print (S)
# # print the results [1, 2, 3,' fjdkaj ',' I'm for admission '' fdsaeddd ', 1234,' ffdsaecc ']

# ---------------------------------------- ----

# insert by extend iteration
# S = [, 2, 3, 'fjdkaj', 'fdsaeddd', 1234, 'ffdsaecc']
# s.extend ( 'I am your father') will be split into # I inserted each element separately, is that you, dad, dad
# s.extend (123) # error will be larger than the number of elements in an iterative Int is not available.
# S.extend ([1,2,3]) # list will be split into a single element, are inserted
# Print (S)

# ------------------- -------------------------

# delete pop delete according to index, and anti-back value in return value can be assigned a variable
# s = [1, 2, 3, 'fjdkaj', 'fdsaeddd', 1234, 'ffdsaecc']
# s.pop (2) # brackets write the index, you can remove elements corresponding to the index, and can counter back to a variable
# s.pop () # brackets do not write index, the default is to delete the last one, and you can delete the element back to a variable anti-
# Print ()
# ------------------- -------------------------

# deleted by deleting elements remove #
# s = [1,2,3, 'fjdkaj ', 'fdsaeddd', 1234, 'ffdsaecc']
# s.remove (1234) # in the list of '1234' element removed
# Print (S)
# -------------------- ------------------------

# puncturing clear clear list

# s = [1,2,3, 'fjdkaj ', 'fdsaeddd ', 1234' ffdsaecc ']
# S.clear () # clear the list, but the list also, but is an empty list
# Print (S)
# ------------------------ --------------------

# deletion del deletion list
# S = [l, 2,3, 'fjdkaj', 'fdsaeddd', 1234, 'ffdsaecc']
# del s # delete the whole list

# del s [0: 4] # slice delete multiple items in the list
# print (s) # print will complain, has already started since deleted, this variable does not exist s

# - ------------------------------------------

# change (direct change)
# S = [l, 2,3, 'fjdkaj', 'fdsaeddd', 1234, 'ffdsaecc']
# S [0] = 'One' # direct change, find the corresponding index, a direct replacement
# s [1] = [ ' one ', 1,2,3] # can also change list list, direct replacement
# Print (S)
# ------------------------- -------------------

# change (sliced change)
S = # [l, 2,3, 'fjdkaj', 'fdsaeddd', 1234, 'ffdsaecc']
# S [0:. 3] = 'One' # 0-3 to come out, you change the fill, but , to change is iterative, a minimum element unit of
# s [0: 3] = [1,2,3,8,8,] ## out to 0-3, iterative fill your smallest element of the list However, iterative to change to the minimum element unit
# print (s) # print content: [ 'o', 'n ', 'e', 'fjdkaj', 'fdsaeddd', 1234, 'ffdsaecc']
# --------------------------------------------

# check (for i in)
# S = [l, 2,3, 'fjdkaj', 'fdsaeddd', 1234, 'ffdsaecc']
# for I in S: check iteration #
# Print (I)
# Print (S [0: 2]) slice # check

# II. public method
# len () to check a few elements (or the length of the list)
# S = [l, 2,3, 'fjdkaj', 'fdsaeddd', 1234, 'ffdsaecc']
# L = len (p)
# print (I)

# Count () to check a list element appears several
# S = [l, 2,3, 'fjdkaj', 'fdsaeddd', 1234, 'ffdsaecc']
# s.count NUM = (2)
# Print ( NUM)

# index () to find the index of the element through
# S = [l, 2,3, 'fjdkaj', 'fdsaeddd', 1234, 'ffdsaecc']
# NUM = s.index ( 'fjdkaj') will not find # error
# Print (NUM)

# ------------------------------------------- -

# sort

# inversion
# s = [1,8,3,12,3,4,24,55,37,22]
# s.reverse () inverted list #
# Print (S)

# descending
# s = [1,8,3,12,3,4,24,55,37,22]
# S.sort (reverse = True) # reverse order
# Print (S)

# positive sequence
S = # [1,8,3,12,3,4,24,55,37,22]
# s.sort () # what is not written in brackets is the sort of positive sequence
# Print (S)



# III. List nested
# needs a
# li = [ 'xiaobai', ' two small', 'Wang', [ 'ABC', 'ddd', 121,774], 432]
# Print (Li [. 1] [. 1]) # Get a list of 'small two' two '

# demand II
# li = [' xiaobai ', ' two small ',' Wang ', [' ABC ',' ddd ', 121,774], 432]
# Print ( li [0]) # print queue index '0' of the character string.
# name = Li [0] .capitalize () # the index '0' and capitalized string assigned to the variable name
# Print (name ) # print variable name
# Li [0] = variable name replacing to 0 the index bits name # character toe
# print (li) # print list
. # # Ps may be directly written: li [0] = li [ 0].capitalize ()

# needs three
# Li = [ 'xiaobai', ' two small', 'Wang', [ 'ABC', 'ddd', 121,774], 432]
# Li [2] = Li [2] .replace ( 'WANG', ' bastard ') # list index' 2 '' Wang 'into a' little bastard '
# Print (Li)

# demand four
# li = [' xiaobai ', ' two small ',' Wang ' , [ 'ABC', 'ddd', 121,774], 432]
# Li [3] [0] = Li [3] [0] .upper () index list # '3' in the list of the index '0' 'abc' replace all uppercase
# print (li)

# Tuple also called the read-only list, the query can be recycled, can be sliced 
# son can not be changed, grandchildren may be able to change, that is to say, the whole list in the tuple can not be changed, but elements within the tuple can be changed
# tu = (l, 2,3, 'abvc', [2,3,4, 'xiaobai'], 'Zhang')
# TU [. 4] [. 3] TU = [. 4] [. 3] .upper () # meta group list index '4' is the index '3' 'xiaobai' to the entire capital
# Print (TU)
# TU [4] .append ( '2B') # tuple index ' list 4 'is in a new filling element (string)
# Print (TU)

# S.join () # iterative element within the object can be connected with other strings to form a new string
# can using this method would be translated into strings listing
# string is connected to the special string
# = S 'ABCDEFG'
# J = '_'. the Join (S)
# Print (J)

# listing to string
# tu = [ '1,1,1,1', '222', 'xiaobai'] # Note that if the list of elements of type int, being given.
# = L ''.the Join (TU)
# Print (L)

# Range corresponds to a sequential list of numbers

# For i in range (0,10) : # range ( start, end) if you can not write from the beginning 0 0
# Print (i)
#
# for i in the Range (10,0, -1): # take down, If that is even put down into -1 -2
# Print (I)
#
# for I in Range (0, 10): odd Zhengqu #
# Print (I)
#
# for I in Range (0,10, -1): # metamorphosis face questions, the result is what is not output, not given.
# Print (I)

Guess you like

Origin www.cnblogs.com/guanshou/p/11939386.html