In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
# string method: the function of center# is to center the string within a certain width area # this method is the same as the ^ in the format we used earlier # ^ print (") #
< hello >#
< hello >Print (".format (" hello ")) #
< hello ># print (") # print (" .format ("hello")) #-look for substrings in a large string if found The find method returns the position where the first character of the substring appears in the large string, which is the index if it is not found. Then the find method returns-1find method has three parameters, the first is the substring to find, the second parameter is the start index, the third parameter is the end index left closed right open # string method: finds = "hello world" print (s.find ("world")) # 6w the location index is 6 print (s.find ("abc")) #-1 does not return-1 print (s.find ("o")) # 4 returns the index print of the first 0 (s.find ("o") (6)) # 7 the second 0 appears in the 7th position print (s.find ("l", 5pr 9)) #-1print (s.find ("l", 5p 10)) # 9 left closed and right open-# string method: join# is used to connect elements in the sequence Inverse method of split method list = ["a", "b", "c", "d" "e"] s ='* 'print (s.join (list)) # a*b*c*d*eprint ("xy" .join (list)) # axybxycxydxye# C:\ abc\ xyz# / abc/xyz# c:\ usr\ local\ nginx\ # / usr/local/nginx/# this join is very helpful in our linux and windows how the paths of different operating systems are shown in python code: to represent a linux environment The path # defines a tuple dirs = ('' 'usr','local','nginx','') linuxPath =' / '.join (dirs) print (linuxPath) # / usr/local/nginx/windowPath = (' CJV'+'\\ '.join (dirs)) print (windowPath) # C:\ usr\ local\ nginx\ # numList = [1JI 2JI 3JI 4 5 print 6] # this escape exception must be converted into a string # print ("a" .join (join))-# string method: the split method is split into a list S1 = "a b c d e f" print (S1. Split () # ['a' Path = "/ usr/local/nginx" pathList = path.split ('/') print (pathList) # [', 'usr',' local' 'nginx'] windowPath = "D:" + "\\" .join (pathList) print (windowPath) # D:\ usr\ local\ nginx---lower: make all English letters lowercase upper: make all English letters uppercase capwords Function: capitalizes the first letter in an independent string: lower, Upper and capwords function print ("HEllo" .lower ()) # helloprint ("hello" .upper ()) # HELLOlist = ["Python" "Ruby", "Java" "KOTLIN"] if "Kotlin" in list: print ("Kotlin found") else: print ("Kotlin not found") # No Kotlin case sensitive for lang in list: # loop through so that every word is converted to lowercase if "kotlin" = = lang.lower (): print ("found Kotlin") # found Kotlin break From string import capwordss = "i not only like Python, but also like Kotlin" print (capwords (s)) # I Not Only Like Python, But Also Like Kotlin---replace method: replaces the same substring that appears in a string The most common thing here is to replace all the spaces entered by the console with blanks. For example: "" IDE = input ('Please enter the name of IDE') findIDE = IDE.replace (','). Lower () # converts the input space to blank and the input value to lowercase "" strip method: intercepts the space before and after # string method: replace and strips = "abcdaedf" print (s.replace ("a", "12345")) # 12345bcd12345edfprint (s.replace ("xyz") "aa") # abcdaedf returns the original string print ("geekori.com" .strip ()) # geekori.comprint ("
< geekori.com >".strip () #
< geekori.com >Will only intercept the spaces before and after Will not intercept the middle space langList = ["python", "java", "ruby", "scala" "perl"] lang = "python" if lang in langList: print ("python found") else: print ("python not found") # not found pythonif lang.strip () in langList: print ("python found") else: print ("python not found") # found pythons = "* * $$* Hello * World * * $" print (s.strip ("* $")) # Hello * World "* $"-# string method: translate and maketrans# translate: replace single character maketrans method: convert to dictionary s = "I not only like python" But also like kotlin. "table = s.maketrans (" ak "," * $") # what he means is to replace a with * k with $print (table) # {97: 42,107: 36} first forward to the dictionary ACLLZ (s.translate (table)) # I not only li$e python, but * lso li$e $otlin.table1 = s.maketrans (" ak "," * $") ") # the third parameter deletes the whole meaning: convert a to *, k to $and delete the spaces in the middle print (table1) # {97: 42,107: 36,32: None} print (s.translate (table1)) # Inotonlyli$epython,but*lsoli$e$otlin.# delete all spaces after
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.