String str
######################################################
# 1 Initial capital letters
# test = "ALex"
# v = test.capitalize ()
# print (v)
# 2 All lowercase, casefold, many unknown to corresponding lowercase
# V1 = Test.casefold ()
# print (v1)
# v2 = Test.lower ()
# Print (v2)
# 3 Set the width and center the content
# 20-Finger total length
# * Blank unknown padding, one character, dispensable
# v = test.center (20, "medium")
# print (v)
# test = "Alex"
# v = test.ljust (20, "*")
# print (v)
# test = "Alex"
# v = test.rjust (20, "*")
# print (v)
# test = "Alex"
# v = test.zfill (20)
# print (v)
# 4 Go to the string and look for the number of occurrences of the subsequence
# test = "ALEXALEXR"
# v = test.count (' ex ')
# print (v)
# test = "ALEXALEXR"
# v = test.count (' ex ', 5,6)
# print (v)
# 5 What's the end?
# Start with what?
# test = "Alex"
# v = test.endswith (' ex ')
# v = test.startswith (' ex ')
# print (v)
# 6 Expandtabs, segmentation 20,
# test = "Username\temail\tpassword\nlaiying\[email protected]\t123\nlaiying\[email protected]\t123\nlaiying\[email Protected]\t123 "
# v = test.expandtabs (20)
# print (v)
# 7 Start looking backwards, find the first one, get its unknown
# > or >=
# test = "Alexalex"
# Not found-1
# v = test.find (' ex ')
# print (v)
# 8 Index not found, error ignored
# test = "Alexalex"
# v = test.index (' 8 ')
# print (v)
# 9 formatting, replacing placeholders in a string with the specified values
# test = ' I am {name} ', age {A} '
# Print (test)
# v = test.format (name= ' Alex ', a=19)
# print (v)
# test = ' I am {0}, age {1} '
# Print (test)
# v = Test.format (' Alex ', 19)
# print (v)
# 10 formatted, incoming value {"Name": ' Alex ', ' a ': 19}
# test = ' I am {name} ', age {A} '
# V1 = Test.format (name= ' DF ', a=10)
# v2 = Test.format_map ({"Name": ' Alex ', "a": 19})
# 11 Whether the string contains only letters and numbers
# test = "123"
# v = test.isalnum ()
# print (v)
# str
# 12 is the letter, man
# test = "AS2DF"
# v = test.isalpha ()
# print (v)
# 13 Whether the current input is a number
# test = "Two" # 1,②
# V1 = Test.isdecimal ()
# v2 = Test.isdigit ()
# v3 = Test.isnumeric ()
# Print (V1,V2,V3)
# 14 Whether there are non-visible characters
# \ t tab
# \ nthe line-break
# test = "Oiuas\tdfkj"
# v = test.isprintable ()
# print (v)
# 15 Determine if all spaces are blank
# test = ""
# v = test.isspace ()
# print (v)
# 16 Judging if it's a title
# test = "Return True if all cased characters in S was uppercase and there is"
# V1 = Test.istitle ()
# print (v1)
# v2 = Test.title ()
# Print (v2)
# v3 = V2.istitle ()
# Print (v3)
# 17 * * * * * stitch each element of a string with a specified delimiter
# test = "You are the wind, I am the Sand"
# Print (test)
# # t = '
# v = "_". Join (Test)
# print (v)
# 18 Determine if all are case and converted to uppercase and lowercase
# test = "Alex"
# V1 = Test.islower ()
# v2 = Test.lower ()
# print (v1, v2)
# V1 = Test.isupper ()
# v2 = Test.upper ()
# Print (V1,V2)
# 19 Remove the specified string
# Limited Maximum Matching
# test = "XA"
# # v = test.lstrip (' xa ')
# v = test.rstrip (' 9lexxexa ')
# # v = test.strip (' xa ')
# print (v)
# Test.lstrip ()
# Test.rstrip ()
# Test.strip ()
# Remove left and right blanks
# v = Test.lstrip ()
# v = Test.rstrip ()
# v = Test.strip ()
# print (v)
# Print (test)
# remove \ t \ n
# v = Test.lstrip ()
# v = Test.rstrip ()
# v = Test.strip ()
# print (v)
# 20 Correspondence Relation substitution
# test = "Aeiou"
# test1 = "12345"
# v = "ASIDUFKASD;FIUADKF;ADFKJALSDJF"
# m = Str.maketrans ("Aeiou", "12345")
# New_v = v.translate (M)
# Print (NEW_V)
# 21 divided into three parts
# test = "TESTASDSDDFG"
# v = test.partition (' s ')
# print (v)
# v = test.rpartition (' s ')
# print (v)
# 22 is divided into a specified number
# v = test.split (' s ', 2)
# print (v)
# Test.rsplit ()
# 23 Split, only according to, True,false: whether to keep line breaks
# test = "ASDFADFASDF\NASDFASDF\NADFASDF"
# v = test.splitlines (False)
# print (v)
# 24 begins with XXX, ends with XX
# test = "Backend 1.1.1.1"
# v = test.startswith (' a ')
# print (v)
# Test.endswith (' a)
# 25 uppercase and lowercase conversions
# test = "ALex"
# v = test.swapcase ()
# print (v)
# 26 Letters, numbers, underline: identifier Def class
# a = "def"
# v = a.isidentifier ()
# print (v)
# 27 replaces the specified string with the specified string
# test = "Alexalexalex"
# v = test.replace ("Ex", ' BBB ')
# print (v)
# v = test.replace ("Ex", ' BBB ', 2)
# print (v)
###################### 7 Basic Magic ######################
# join # ' _ '. Join ("ASDFASDF")
# split
# find
# Strip
# upper
# lower
# Replace
###################### 4 Grey Magic ########################
# test = "Zheng Jianwen sister has a kind of come to me"
# One, for loop
# for variable name in string:
# variable Name
# break
# continue
# index = 0
# while index < Len (test):
# v = test[index]
# print (v)
#
# index + = 1
# print (' ======= ')
# for ZJW in test:
# Print (ZJW)
# test = "Zheng Jianwen sister has a kind of come to me"
# for item in test:
# Print (item)
# break
# for item in test:
# continue
# Print (item)
# Two, index, subscript, get a character in a string
# v = test[3]
# print (v)
# Three, Slice
# v = test[0:-1] # 0=< <1
# print (v)
# Four, get the length
# Python3:len Gets the current string consisting of several characters
# v = len (test)
# print (v)
Note
# len ("Asdf")
# for Loop
# index
# slices
# v. To obtain a continuous or discontinuous number,
# Python2 created directly in the content
# Only A For loop is created in Python3
# r1 = Range (10)
# r2 = range (1,10)
# r3 = Range (1,10,2)
# helps create sequential numbers by setting the step size to specify discontinuities
# v = range (0, 100, 5)
#
# for item in V:
# Print (item)
######################## #练习题 ########################
#根据用户输入的值, the output of each character and the index where the current character is located
# test = input (">>>")
# for item in test:
# Print (item)
# Print the text corresponding to the index:
# test = input (">>>")
# print (test) # test = Qwe test[0] test[1]
# l = len (test) # L = 3
# print (L)
#
# r = Range (0,l) # 0,3
# for item in R:
# Print (item, Test[item]) # 0 q,1 w,2 E
# test = input (">>>")
# for item in range (0, Len (test)):
# Print (item, Test[item])
###################### 1 Dark grey magic #####################
# Once a string is created, it cannot be modified
# once modified or spliced, it will cause the string to be regenerated.
# name = "Zhengjianwen"
# age = "18"
#
# info = name + age
# Print (info)
Python Basics-string