In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
1. Common string operations
# string operation name = "my name is kk" print (name.capitalize ()) # > > My name is kk#capitalize () # initials print (name.count ("a")) # > 1#count ("a") counts the number of aprint (name.center (50, "-")) # >-my name is kk-#center (50) "-") A total of 50 "-" are printed, with characters corresponding to name placed in the middle of print (name.endswith ("k")) # > True#endswith () ending # expandtabs (tabsize = 10), followed by 10 spaces name = "my name is kk" print (name.find ("name")) # > > 3#find () string can also be sliced names = "my name is {name} and {year}" print (names.format (name = 'kk') Year = 27)) # > > my name is kkand 27#format () format print (names.format_map ({'name':'kk','year':'27'})) # format_map () print (' ab123'.isalnum ()) # > True#isalnum () does this contain Arabic numerals You cannot use the special character print ('ab'.isalpha ()) # > > True#isalpha () to judge whether the English character print (' ab1'.isdecimal ()) # > False#isdecimal () is a decimal isdigit () is an integer print ('ab123'.isidentifier ()) # > > True#isidentifier () to determine whether it is a legal identifier print ("aaa" .islower ()) # > True#islower () Lowercase print ("33" .isnumeric ()) # > True#isnumeric () determines whether it is a number print ("My Name" .istitle ()) # the first letter is all uppercase # > Trueprint ("MY NAME" .isupper ()) # > True# is all uppercase print ("+" .join (['1'') ) # > 1. Print (name.ljust (50)) is often used in my name is kk**print (name.rjust (50)) '-')) # > >-- my name is kkprint ("AA" .lower () # > aaprint ("aa" .upper ()) # > > AAprint ("\ nAA") print ("\ nAA" .lstrip ()) # to the left space to wrap print ("AA\ n") print ("AA\ n" .rstrip ()) # to the right blank Print ("\ n AA\ n") print ("\ n AA\ n" .strip ()) # remove the left and right space newline character print ("geng". Replace ("g") "G", 1)) # replace The last 1 means replacing only the first print ("alex li" .rfind ("l")) # > finding the first l-corresponding subscript print ("1-2-3-4" .split ("+")) from right to left. Split ("+")) # > ['1','2','3','4']
2. the use of dictionaries
# use of dictionaries # Note: dictionaries are unordered Because there is no subscript info = {'s 1: "Xiao Li",'s 2: "Xiao Zhang",'s 3: "Xiaomi",} print (info) b = {'s 1: "kk", 22 kk 100, 1:1,} info.update (b) print (info) print (info.items ()) # result: {'s 1: 'Xiao Li,' s 2: Xiao Zhang Kk', 1: 1, S2: Xiao Zhang, S3: Xiaomi, 22: 100} dict_items ([('s 1, 'kk'), (1, 1), (' s 2, Xiao Zhang'), ('s 3, 'Xiaomi), (22) ) # print (info ['S1']) # info ["S1"] = "Little plum" # info ['s4'] = "kk" # print (info) # Delete # del info [' s3'] # info.pop ('s2') # Standard deletion pose # info.popitem () # any one of the # print (info) # > > {' s 4': 'kk' 'S1 plum'} # print (info.get ("S1")) # query whether this is in the dictionary # > Little plum # print ('s1' in info) # > True
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.