python base ---- day1 (magic strings)

#expandtabs, punctuation 20

1 test = "username\temail\tpassword\nlishijie\[email protected]\t123"
2 v = test.expandtabs(20)
3 print(v)

           (20) represents letters username is 8, a space 20 remaining complement (i.e., spaces 12)

           \ T denotes the row \ n branch

 

#isalpha all letters, Chinese characters represent true

test = "lishijie"
v = test.isalpha()
print(v)

 

Whether the current input is a digital #

1 test = ""
2 v1 = test.isdecimal()
3 v2 = test.isdigit()
4 v3 = test.isnumeric()
5 print(v1,v2,v3)

 

# Whether there is a character can not be visualized (eg: \ t tab \ n newline)

1 test = "djhsfih\tkjjdgh"
2 v = test.isprintable()
3 print(v)

 

# Judge whether all spaces

test = "     "
v = test.isspace()
print()

 

# Determine whether the title (all caps)

test = "i am a talent"
v1 = test.istitle()
print(v1)
v2 = test.title()
print(v2)
v3 = v2.istitle()
print(v3)

 

#### by each element string according to a specified splicing delimiter

= Test " Moonlight " 
Print (Test) 
T = '  ' 
V = t.join (Test)
 Print (V)

 

 

# Set the width and center the contents

On behalf of the total length of # 20

# * Fill gaps unknown, a character, optional

test = "lishijie"
v = test.center(20,"*")
print(v)

# Put the word on the left

test = "lishijie"
v = test.ljust(20,"*")
print(v)

# Put the right word

test = "lishijie"
v = test.rjust(20,"*")
print(v)

 

 

 

# Islower determine whether it is lowercase, lower lowercase

test = "LIshijie"
v1 = test.islower()
v2 = test.lower()
print(v1,v2)

isupper determine whether or not all uppercase, upper capitalize

test = "LIshijie"
v1 = test.isupper()
v2 = test.upper()
print(v1,v2)

 

Alternatively replece (brackets 2, replacing the former two shown)

test = "lishijie"
v = test.replace("shijie","qihao")
print(v)
test = "lishijielishijielishijie"
v = test.replace("shijie","qihao",2)
print(v)

 

 ######################################### seven basic magic ##### ##########################

 join

split

find

strip

upper

lower

replace

#######################################other########## ##################

# Index, index (starting from 0) acquiring a character string in a

test =  "lishijie"
v = test[3]
print(v)

  

Slice #: take a range [1: 3] is greater than or equal to 1 and less than 3

test = "lishijie"
v = test[1:2]
print(v)

 

# Len Gets the current string of several characters

test = "lishijie"
v = len(test)
print(v)

 

#for cycle

= the Test " Liu Xiangyu is a sucker " 
for Item in the Test:
     Print (Item)

 

 

####################### in a string, remember the magic 11 ################# #########################

***** Once the string is created, can not be modified
     Once created or stitching, can cause regenerate string

Guess you like

Origin www.cnblogs.com/lishijie-/p/11619343.html