Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Python full stack strings and lists

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains the "Python full stack string and list how to use", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Python full stack string and list how to use" it!

1. Format format _ fill symbol is formatted using 1.1 format

Formatted format of a string

# (1) Sequential passing parameters "" {} is the placeholder in format "" strvar = "{} fired a shot at {} and died by drinking eggs" .format ("Zhao Shenyang", "need to be guaranteed") print (strvar) # (2) Index passed parameter strvar = "{1} fired a shot into {0}, drank eggs and died" .format ("Zhao Shenyang" "need to guarantee") print (strvar) # (3) keyword parameter strvar = "{who1} touch {who2}, turn around slap" .format (who1= "Wang Wei", who2= "Ma Chunni") strvar = "{who1} touch {who2}, turn around slap" .format (who1= "Ma Chunni") Who2= "Wang Wei") print (strvar) # (4) Container type data (list or Yuanzu) pass parameter # method 1 strvar = "{0 [0]} touch {1 [1]}, hey hey smile, have a chance" .format ("Zhao Fengzong", "Zhao Shichao", "Yang Yuantao"), ("Wang Yuhan" "Wang Tongpei") print (strvar) # method 2 (recommended) strvar = "{group1 [0]} touch {group2 [1]}, hey smile, there's a chance" .format (group1= ["Zhao Fengchao", "Zhao Shichao", "Yang Yuantao"], group2 = ("Wang Yuhan", "Wang Tongpei") print (strvar) # method three (recommended) note one. If the container is a dictionary, there is no need to add quotation marks when taking values by key. When passing subscript values, you cannot use the negative sign (reverse index) strvar = "{group1 [zfy]} touch {group2 [- 1]}, hey hey smile, there's a chance" .format (group1= {"zfy": "Zhao Fengzong", "zsc": "Zhao Shichao"}, group2 = ("Wang Yuhan", "Wang Tongpei") print (strvar) 1.2 format fill symbol

The use of fill symbols for format (^ >

< ) """^ 原字符串居中显示>

The original string is displayed on the right

< 原字符串居左显示{who:*^10}* : 填充的符号^ : 原字符串居中显示10: 原字符串长度 + 填充符号的长度 = 10"""strvar = "{who:*^10}去长春长生医药公司,{do:>

> 10}, it feels like {feelpura! List [:] full format: [start index: end index: interval value] (1) [start index:] truncate from the start index to the last of the list (2) [: end index] before the end index (end index-1) (3) [start index: end index] intercept from the start index to the end index Before quoting (end index-1) (4) [start index: end index: interval value] intercept list element values (5) [:] or [::] intercept all list values at specified intervals from the start index to the end index "" lst = ["Meng Fanwei" "Kang and the public", "Zhang Yu", "Zhao Shenyang", "need to be guaranteed", "Liang Xinyu" "Shen Siyu"] # (1) [start index:] from the start index to the last res of the list = LST [2:] print (res) # (2) [: end index] truncate from the beginning to the end of the index (end index-1) res = lst [: 3] print (res) # (3) [start index: end index] from start index to end index (end index) Quote-1) res = lst [3:5] print (res) # (4) [start index: end index: interval value] intercept list element values at a specified interval before starting index truncation to end index # forward intercept res = lst [:: 5] print (res) # 051 reverse intercept res = lst [::-3] #-1-4-7print (res) # (5) [:] or [:] intercept all lists res = lst [:] res = lst [::] print (res) # (4) get the list (the same tuple) # 01 2lst = [10zheng20 2lst 30] #-3-2-1print (lst [- 1]) # (5) modify the list (slicable) lst = ["Meng Fanwei" "Kang and Zhong", "Zhang Yu", "Zhao Shenyang", "need to guarantee", "Liang Xinyu", "Shen Siyu"] # change a single value lst [1] = "Chen Lu" print (lst) # 1. Change multiple values (if slicing is used, the data must be Iterable iterated data) # lst [1:4] = ["Sun WuKong", "Zhu Bajie", "Baigujing"] lst [1:4] = "Hello" print (lst) # 2. Change multiple values (with step size) "" with step size slice modification, cut out a few elements and modify several elements in the same number. "lst = [" Meng Fanwei "," Kang and Zhong "," Zhang Yu "," Zhao Shenyang "," need to be guaranteed "," Liang Xinyu " "Shen Siyu"] "036"lst [:: 3] =" abc "# lst [:: 3] =" ab "errorprint (lst) # (6) list deletion (slicable) lst = [" Meng Fanwei "," Kang and Zhong "," Zhang Yu "," Zhao Shenyang "," need to guarantee "," Liang Xinyu "," Shen Siyu "] # 1. Delete one # del lst [2] # print (lst) # 2 at a time. Delete a bunch of # del LST [1:-1] # print (lst) # 3 at a time. Note that res = LST [1:-1] del res # removes the variable res, which has nothing to do with the list. Print (lst) # extra attention tup = (1L2, LJ 3, 4, [10, LJ 11, 12]) print (tup [- 1]) tup [- 1] [- 1] = 13print (tup) 4. Related functions of the list

List-related functions

# list-related functions # add # append add a new element lst = ["Zhao Shenyang"] lst.append ("Shen Siyu") print (lst) # insert to the end of the list insert elements lst = ['Zhao Shenyang', 'Shen Siyu'] lst.insert (1, "Wang Wei") print (lst) # extend iteration to append all elements iteratively (container type data) before the specified index Range object, iterator) "" lst = ['Zhao Shenyang', 'Shen Siyu'] # tup = (1jing2phi3) # lst.extend (tup) # strvar = "abc" # lst.extend (strvar) lst.extend (range (3)) print (lst) # delete # 1.pop delete elements through the specified index, if there is no index to remove the last (recommended) lst = ["Cao Jingyi", "Wang Zhiguo", "Deng Peng" "reasonable"] # does not specify a subscript. By default, delete the last res = lst.pop () print (res) print (lst) # specify the subscript, delete a specific element res = lst.pop (1) print (res) print (lst) # 2.remove, and delete the first lst = ["Cao Jingyi", "Wang Zhiguo", "reasonable", "Deng Peng" if there are multiple identical elements. "reasonable"] res = lst.remove ("reasonable") print (res) print (lst) # 3.clear clear list lst = ["Cao Jingyi", "Wang Zhiguo", "reasonable", "Deng Peng", "reasonable"] lst.clear () print (lst) # check other related functions in the 4.py# list # index to get the index of a value in the list lst = ["Cao Jingyi", "Wang Zhiguo", "reasonable", "Deng Peng" "reasonable", "Deng Penghui", "Deng Penglan", "reasonable"] res = lst.index ("reasonable") res = lst.index ("reasonable", 3) res = lst.index ("reasonable") 3 res 6) # 3 4 ranking res = lst.index ("reasonable") errorprint (res) # count calculates the number of occurrences of an element res = lst.count ("reasonable") # the concept of no scope print (res) # sort sorts the list lst = [- 90 Majo100 Lst.sort () # sort from small to small (lst.sort (reverse=True) print (lst) # sort strings (according to ascii code) lst = ["kobi", "james", "jordon", "yaoming", "yi"] lst.sort () print (lst) # whether it is possible to sort Chinese (knowing no rules) lst = ["Wang Wen") "Cai Xukun"] lst.sort () print (lst) # reverse list reversal operation lst = [1Magne2, "a", "Cai Xukun", "Yi Qianxi"] lst.reverse () print (lst) 5. Deep and shallow copy

Deep and shallow copies of the list

# A deep and shallow copy of the list "" a = 100b = aa = 200print (b) lst1 = [1meme 2mai 3] lst2 = lst1lst1.append (4) print (lst2) "" # 1. Shallow copy of the import copy "" module. Method () method of the same name "" # method 1 (recommended) "" lst1 = [1J 2jue 3] lst2 = copy.copy (lst1) lst1.append (10) print (lst2) print (lst1) "" # method II "" lst1 = [1M 2M 3] lst2 = lst1.copy lst1.append (11) print (lst1) print (lst2) "" # 2. Deep copy "" make a separate copy of the container elements at all levels, and place them in a separate space "# phenomenon lst1 = [1 copy.copy (lst1) lst1 [- 1]] lst2 = copy.copy (lst1) lst1 [- 1] .append (77) lst1.append (8888) print (lst2) print (lst1)"import copylst1 = [1, 2, 4, 5] 6]] lst2 = copy.deepcopy (lst1) lst1 [- 1] .append (999) print (lst2) print (lst1) # Deep copy of other containers lst1 = (1) copy.deepcopy (lst1) lst1 [- 1] ["b"] .append (30) print (lst1) print (lst2) "Summary: shallow copy: only copy all the elements in the first-level container to create a separate space independently. Deep copy: make a separate copy of all the elements in the container at all levels to form a separate space "tuple only two methods count index use the same list"

Tip: d forced to receive integer data, if it is not an integer, it will report an error # because 9.5 is a decimal strvar = "Liu Yifeng bought% d toilet water bubble feet last night". Formar (9.5) print (strvar) # does not report an error 3.88 will be strongly converted to int type 3strvar = "Liu Yifeng bought% d toilet water soaked feet last night"% (3.88) print (strvar) isdecimal strvar = "123.34" res = strvar.isdecimal () print (res) this value is False, because. You will think that it is not a number "123" and this will be considered a pure number 6. Small exercise (1) string-related exercise questions: # string-related exercise 1. The variable name = "aleX leNb" completes the following operations: remove the spaces on both sides of the value corresponding to the name variable and output the processing result 1) remove the "al" on the left side of the name variable and output the processing result 2) remove the "Nb" on the right side of the name variable, and output the processing result 3) remove the an and the last "b" at the beginning of the name variable, and output the processing result 4) determine whether the name variable begins with "al" And output result 5) judge whether the name variable ends with "Nb", and output result 6) replace all "l" with "p" in the corresponding value of name variable, and output result 7) replace the first "l" in the corresponding value of name variable with "p", and output result 8) divide the corresponding value of name variable according to all "l", and output the result. Name = "aleX leNb" res = name.split ('l') print (res) 9) splits the value of the name variable according to the first "l" and outputs the result. 10) uppercase the value of the name variable, and output the result 11) lowercase the value of the name variable, and output the result 12) capitalize the first letter "a" of the name variable, and output the result 13) judge that the value letter "l" of the name variable appears several times And output result 14) if it is judged that the first four bits "l" of the value corresponding to the name variable appear several times, and output the result 15) find the index corresponding to "N" from the value of the name variable (if it cannot be found, an error will be reported) And output result 16) find the index corresponding to "N" from the value of the name variable (return-1 if not found) output result 17) find the index corresponding to "X le" from the value corresponding to the name variable And output result 18) Please output the 2nd character of the value corresponding to the name variable? 19) Please output the first 3 characters of the value corresponding to the name variable? 20) Please output the last 2 characters of the value corresponding to the name variable? 21) Please output the index position of "e" in the value corresponding to the name variable? 2. Implement an integer addition calculator (the addition of two numbers): for example: content = input ("Please enter content:") user input: 5 + 9 or 3 + 9 or 5 + 6, then split and then calculate 3. Upgrade question: to achieve an integer addition calculator (multiple numbers add): for example: content = input ("Please enter content:") user input: 59.6 + 12 + 13, and then split and then calculate. 4. Calculates how many integers (in single digits) are included in the user input. For example: content = input ("Please enter content:") # such as fhdal234slfh98769fjdla5. Waiting for user input, does it contain sensitive characters? If there are sensitive characters that prompt "Please re-enter sensitive characters", sensitive characters: "pink tender" and "hammer" 6. Making interesting template program requirements: waiting for users to enter name, location, hobby assembly data to print out: dear and dear xxx, most like to xxx in xxx place

String related exercise answer:

# string related exercises # 1. The variable name = "aleX leNb" does the following: name = "aleX leNb" # removes the spaces on both sides of the value corresponding to the name variable, and outputs the processing result name.strip () # 1) removes the "al" on the left side of the name variable and outputs the processing result name.lstrip ("al") # 2) removes the "Nb" on the right side of the name variable, and outputs the processing result name.rstrip ("Nb") # 3) removes the an and the last "b" at the beginning of the name variable. And output the processing result print (name [1:-1]) # 4) to determine whether the name variable begins with "al", and output the result res = name.startswith ("al") print (res) # 5) to determine whether the name variable ends with "Nb", and output the result res = name.endswith ("Nb") print (res) # 6) replace all "l" in the value corresponding to the name variable with "p". And output the result res = name.replace ("l", "p") print (res) # 7) replace the first "l" in the value corresponding to the name variable with "p", and output the result res = name.replace ("l", "p", 1) print (res) # 8) divide the corresponding value of the name variable according to all "l" and output the result. Res = name.split ("l") print (res) # 9) splits the value of the name variable according to the first "l" and outputs the result. # string .split ("split character", number of splits) # from left to right print (name.split ("l", 1)) strvar = "you-can-you-up" # from right to left print (strvar.rsplit ("-", 2)) # 10) uppercase the value of the name variable and output the result name.upper () # 11) lowercase the value of the name variable And output the result name.lower () # 12) capitalize the first letter "a" corresponding to the name variable, and output the result print (name.capitalize ()) # 13) to judge that the value letter "l" corresponding to the name variable appears several times. And output the result print (name.count ("l")) # 14) if it is judged that the first four bits "l" of the value corresponding to the name variable appear several times, and output the result print (name.count ("l", 0P4) # 15) find the index corresponding to "N" from the value of the name variable (if it cannot be found, an error will be reported) And output result print (name.index ("N")) # 16) find the index corresponding to "N" from the value of name variable (return-1 if not found) output result print (name.find ("N")) # 17) find the index corresponding to "X le" from the value corresponding to name variable And output the result print (name.find ("X le")) # 18) Please output the second character of the value corresponding to the name variable? print (name [1]) # 19) Please output the first three characters of the value corresponding to the name variable? Print (name [: 3]) # 20) Please output the last two characters of the value corresponding to the name variable? print (name [- 2:]) # 21) Please output the index position of "e" in the value corresponding to the name variable? name = "aleX leNb" print (name.find ("e")) print ("") for i in range (len (name)): if name [I] = "e": print (I) # 2. Implement an integer addition calculator (the addition of two numbers): # for example: content = input ("Please enter:") user input: 5x9 or 3 + 9 or 5 + 6, and then split it and calculate it "content = input (" Please input: ") print (content) a _ line b = content.split (" + ") print (a _ mag b) print (float (a.strip ()) + float (b.strip ()"# 3. Upgrade question: implement an integer addition calculator (adding multiple numbers): # for example: content = input ("Please enter content:") user input: 599 + 6 + 12 + 13, and then split and calculate. "content = input (" Please enter: ") print (content) lst = content.split (" + ") print (lst) total = 0for i in lst: total + = float (i.strip () print (total)" # 4. Calculate several integers in the content entered by the user. # for example: content = input ("Please enter:) # such as fhdal234slfh98769fjdla" content = input ("Please enter:") total = 0for i in content: if i.isdecimal (): total + = 1print (total) "" # 5. Waiting for user input, does it contain sensitive characters? # if there are sensitive characters that prompt "Please re-enter sensitive characters" Sensitive characters: "pink tender", "hammer" # method 1 'lst = ["pink tender" "Hammer"] while True: # reset the sign tag sign = False content = input ("Please enter:") # print (content) "" if content.find ("pink tender") = =-1 and content.find ("hammer") =-1: print ("ok") else: print (" Not ok ")" # small iron hammer for i in lst: if i in content: # set the sign tag to True sign = True break # if the sign tag is True Sensitive, otherwise insensitive If sign = = True: print ("Please re-enter sensitive characters") else: print ("No sensitive characters") break'''print (") # method 2 (unique to python) extra" if you encounter break during the loop and temporarily terminate the loop What the else branch does not execute will execute the else branch "for i in range (3): if I = = 2: breakelse: print (" ok ")" lst = ["pink tender", "hammer"] # trigger break, do not execute else, and do not trigger break. Execute elsewhile True: content = input ("Please enter:") for i in lst: # whenever you find a sensitive word, directly break, you will not go to the else branch if i in content: print ("is a sensitive word Please re-enter ") # terminate the inner for loop break else: print (" not a sensitive word ") # terminate the outer while loop break"# 6. Make interesting template program requirements: wait for the user to enter the name, location, hobby # assembly data print out: dear and amiable xxx Favorite place in xxx xxxwhile True: name = input ("Please enter your name: press Q to quit ~") if name.upper () = "Q": print ("Welcome to play next time ~") break place = input ("Please enter location:") hobby = input ("Please enter your hobby:") Print ("beloved {}" Favorite in {} place {} ".format (name,place,hobby)) (2) list related exercise question: # list related exercise 1.li = [" alex "," WuSir "," xboy "," oldboy "] 1) add the element" seven "to the list and output the added listing 2) Please insert the element" Tony "in the first position of the list. And output the added listing 3) Please change the element in the second position of the list to "Kelly", and output the modified listing 4) Please add each element of the list L2 = [1, "a", 3pr 4, "heart"] to the list li One line of code is implemented, and loop addition is not allowed. 5) Please add each element of the string s = "qwert" to the list li, which is implemented in one line of code and is not allowed to be added in a loop. 6) delete the element "alex" in the list, and output the added listing 7) delete the list, delete the 2nd to 4th elements in the list, and output the second element in the list after deletion, and output the second element in the list, and output the deleted element and the deleted element in listing 9) Please reverse all the elements in the list. And output the inverted listing 10) Please calculate the number of times the "alex" element appears in the list li, and output that number. 2, write the code, with the following list Use slicing to achieve each function li = [1Power3mag2, "a", 4, "b", 5, "c"] 1) form a new list by slicing the li list, L1Mague L1 = [1Magazine 2] 2) form a new list by slicing the li list, L2 L2 = ["a", 4, "b"] 3) by slicing the li list to form a new list L3 L3 = ["1J2" 4) form a new list by slicing the li list, L4, L4 = [3, "a", "b"] 5) by slicing the li list to form a new list, L5, L5 = ["c"] 6) by slicing the li list to form a new list, L6, L6 = ["b", "a", 3] 3, write code There is a list below to implement each function as required. Lis = [2,3, "k", ["qwe", 20, ["K1", ["tt", 3, "1"], 89], "ab", "adv"] 1) capitalize the "tt" in the list lis. 2) change the number 3 in the list to the string "100". 3) change the string "1" in the list into the number 1014 alex li = ["alex", "eric", "rain"] use underscores to concatenate each element of the list into the string "alex_eric_rain" 5. Use the for loop to print out the index of the following list. Li = ["alex", "WuSir", "xboy", "oldboy"] 6. Use the for loop and range to find the numbers within 50 that are divisible by 3, and insert these numbers into a new list. 7. Using the for loop and range from 100 to 10, all even numbers are added to a new list in reverse order, and then the elements of the list are filtered to leave 8. Look for elements in the list li, remove spaces from each element, and find all elements that start with "A" or "a" and end with "c", add them to a new list, and finally print the new list in a loop. Li = ["xboy", "alexC", "AbC", "egon", "riTiAn", "WuSir", "aqc"] 9. Sensitive word list li = ["Zhang San", "Li Si", "Wang er", "pockmarked"] replace the sensitive words in the content entered by the user with * of equal length (Zhang San will replace *) and add them to a list; if the content entered by the user does not have sensitive words, it will be added directly to the new list. 10.li = [1, 3, 4, "alex", [3, 7, "23aa", 8, "xboy"], 5, ('axiomagemagenb')] circularly prints each element in the list and converts it to lowercase, and then loops out the elements in it when you encounter the list. 11.tu = ("alex", [11pr 22, {"K1": 'v1century, "K2": ["age", "name"], "K3": (11p22) 33)}, 44]) a. Describe the characteristics of tuples b. Can the first element "alex" in the tu variable be modified? c. What is the type of value corresponding to "K2" in tu variable? Can it be modified? If you can, add an element "Seven" d. What is the type of value corresponding to "K3" in the tu variable? Can it be modified? If you can, add an element "Seven" to it

List of related exercise answers:

# list related exercises # 1.li = ["alex", "WuSir", "xboy", "oldboy"] li = ["alex", "WuSir", "xboy", "oldboy"] # 1) append the element "seven" to the list and output the added list li.append ("seven") # 2) Please insert the element "Tony" in the first position of the list and output the added list li.insert (0) "Tony") # 3) Please change the element in the second position of the list to "Kelly" and output the modified list li [1] = "Kelly" # 4) Please add each element of the list L2 = [1, "a", 3pr 4, "heart"] to the list li One line of # code implementation, loop addition is not allowed. L2 = [1, "a", 3Jing 4, "heart"] li.extend (L2) print (li) # 5) Please add each element of the string s = "qwert" to the list li, one line of code implementation, does not allow loop addition. S = "qwert" li.extend (s) print (li) # 6) Please delete the element "Tony" from the list and output the added list li.remove ("Tony") print (li) # 7) Please delete the second to fourth elements in the list and output the list after deletion # del li [1:4] # print (li) # 8) Delete the second element in the list And output the deleted element and the list after deletion res = li.pop (1) print (res) print (li) # 9) Please reverse all the elements in the list and output the inverted list li.reverse () print (li) # 10) Please calculate the number of times the "alex" element appears in the list li, and output that number. Print (li.count ("xboy")) # 2, write code, with the following list Use slicing to achieve each function li = [1Power3Magne2, "a", 4, "b", 5, "c"] # 1) form a new list by slicing the li list, L1Magint L1 = [1jin3re2] print (li [: 3]) # 2) by slicing the li list to form a new list L2L2 = ["a", 4 "b"] print (li [3:6]) # 3) form a new list by slicing the li list, L3Mague L3 = ["1Magi 2jing4jin5] print (li [:: 2]) # 4) by slicing the li list, L4 = [3," a "," b "] print (Li [1:-1:2]) # 5) form a new list L5 by slicing the li list L5 = ["c"] print (li [- 1:]) # 6) by slicing the li list to form a new list L6 L6 = ["b", "a", 3] print (li [- 3 li li 2]) # 3, write code There is a list below to implement each function as required. Lis = [2,3, "k", ["qwe", 20, ["K1", ["tt", 3, "1"], 89], "ab", "adv"] # 1) capitalize the "tt" in the list lis. Print (lis [3] [2] [1] [0] .upper ()) # 2) turns the number 3 in the list into the string "100". Lis [3] [2] [1] [1] = "100" # 3) change the string "1" in the list into the number 10 million lis [3] [2] [1] [- 1] = 10 percent print (lis) lis [3] [2] [1] .remove ("1") # first delete lis [3] [2] [1] .append (101) # add print (lis) # 4 alex li = ["alex", "eric" "rain"] # splices each element of the list into a string "alex_eric_rain" #-print ("_" .join (li)) # 2 strvar = "" for i in li: strvar + = I + "_" print (strvar.rstrip ("_")) # 5. Use the for loop to print out the index of the following list. Li = ["alex", "WuSir", "xboy", "oldboy"] #-for i in range (len (li)): print (I) # II for i in li: print (li.index (I)) # 6. Use the for loop and range to find the numbers within 50 that are divisible by 3, and insert these numbers into a new list. A = [] for i in range (50): if I% 3 = 0: a.append (I) print (a) # 7. Using the for loop and range from 100 to 10, all even numbers are added to a new list in reverse order, and then the elements of the list are filtered to leave the number divisible by 4 a = [] for i in range: if I% 4 = 0: a.append (I) print (a) # 8. Look for elements in the list li, remove spaces from each element, and find all elements that start with "A" or "a" and end with "c", add them to a new list, and finally print the new list in a loop. Li = ["xboy", "alexC", "AbC", "egon", "riTiAn", "WuSir", "aqc"] lst2 = [] for j in li: if (j.strip (). Startswith ("A") or j.strip (). Startswith ("a") and j.strip (). Endswith ("c"): lst2.append (j.strip () print (lst2) # 9. Sensitive word list li = ["Zhang San", "Li Si", "Wang er", "pockmarked"] # replace the sensitive words in the content entered by the user with * of equal length (Zhang San will replace *) and add them to a list; if the content entered by the user does not have sensitive words, it will be added directly to the new list. Li = ["Zhang San", "Li Si", "Wang er", "pockmarked"] lst = [] "" while True: strvar = input ("Please enter words:") lst.append (strvar.replace ("Zhang San", "* *"). Replace ("Li Si", "* *"). Replace ("Wang er", "* *"). Replace ("pockmarked") "*") print (lst) "while True: strvar = input (" Please enter words: ") # exit by Q if strvar.upper () =" Q ": break # filter sensitive words for i in li: if i in strvar: strvar = strvar.replace (I Len (I) * "*") # put the processing data into the list lst.append (strvar) print (lst) "" # 10.print ("") li = [1,3,4, "ALEx", [3,7, "23AA", 8, "XBoy"], 5, ("A", "b")] # circularly prints each element in the list and converts it to lowercase If you encounter a list, you will print out the elements in it. For i in li: # determine whether it is a string if isinstance (iMagnestr): print (i.lower ()) # determine whether it is Number elif isinstance (I, (int,bool,complex,float)): print (I) # determine whether it is a container elif isinstance (I, (list,tuple,set) Dict): for j in i: # determines whether the element in the container is a string if isinstance (j Str): print (j.lower ()) # if not, else: print (j) 11.tu = ("alex", [11,22, {"K1": 'v1century, "K2": ["age", "name"] "K3": (11, 22, 33)}, 44]) # a. Describe the characteristics of tuples can be obtained, unmodifiable, ordered # b. Can the first element "alex" in the tu variable be modified? No # c. What is the type of value corresponding to "K2" in tu variable? Can it be modified? If you can, please add an element "Seven" list to change tu [1] [2] ["K2"] .append ("Seven") # d. What is the type of value corresponding to "K3" in the tu variable? Can it be modified? If you can, please add an element of "Seven" tuple, no, thank you for reading, above is the "Python full stack string and list how to use" of the content, after the study of this article, I believe you on the Python full stack string and list how to use this problem has a more profound experience, the specific use of the need for you to practice verification. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report