Day 1 job

after class homework
= name " Alex " 
# removed name spaces on both sides of the value corresponding to the variable, and outputs the processing result 
Print (() name.strip) 

# determines whether the value of the corresponding name begins with "al", and outputs the result 
Print (name.startswith ( " Al " )) 

# determines whether the name corresponds to the value "X" at the beginning, and outputs the result 
Print (name.startswith ( " X- ' )) 

# the value of the variable name corresponds to" 1 "is replaced with" p " , and outputs the result 
name = name.replace ( " L " , " P " )
 Print (name) 

# the name of the corresponding variable value in accordance with "1" is divided, and outputs the result 
List1 = name.split ( ' L ')
 Print (List1) 

# The name becomes a variable value corresponding to upper case, and outputs the result 
Print (name.upper ()) 

# The name corresponding to the variable value becomes lower case, and outputs the result 
Print (name.lower ())
 # Please output name variable corresponding to the second character values 
Print (name [. 1 ]) 

# please output the first three characters of the name variable value corresponding 
Print (name [0:. 3 ]) 

# Please output value of the name corresponding to the variable 2 characters 
Print (name [-2 :]) 

# Please output value corresponding to the variable name in the "e" index position where 
Print (name.find ( " E " )) 

# acquisition sequence, the last character is removed. As Oldboy is acquired oldbo 
S = ' Oldboy ' 
Print (S [0: -1])

Screenshot result Morning


direct1 = { 'name': 'zcj', 'age': 20 }
for key in direct1:
    print(key)
    print(direct1[key])
in the afternoon
= List1 [ ' Tank ' , 18 is, ' Guangdong ' ]
 Print (List1 [2 ])
 Print (List1 [-1 ]) 
str1 = ' My name IS XXX    ' 
Print (str1 [. 3:. 7 ])
 # slice (GU head regardless of the end, step) 

Print (str1 [. 3: 10: 2])   # . 3 ~ (7-1) 

# len length 
Print (len (str1))
 # membership operator in / in Not 
Print ( ' X '  in str1) 

# remove blank Strip () 
# remove the spaces around the string 
print(str1.strip ()) 

# Split () will go to a string according to segmentation rules brackets, each value is then added to the list 
Print (str1.split ( '  ' )) 

for Line in str1:
     Print (Line, = End '' )   # Print parameter default = End '\ n-'; 
                         # End = "" customize the parameters 
# the lstrip removed or left spaces designated symbol 
# the rstrip remove spaces or specified symbol right 
str2 = ' ** My name XXX IS    ' 
Print (str2.rstrip ())
 Print (str2.lstrip ( ' * ' ))
 # all converted into lowercase Lower () 
# convert all lowercase Upper () 
Str3 = 'XXX name IS My ' 
Print (str3.upper ()) 

# startsWith, endsWith 
# determines whether or not the establishment of end to end string 
Print (str3.startswith ( ' My ' ))
 Print (str3.endswith ( ' My ' )) 

str4 = ' My iS XXX name, My Age 18. a iS ' 
str5 = ' My name iS XXX, My Age 18. a iS ' 
# 1. Strip, the lstrip, the rstrip 
# L specified space or removal of the left symbol 
# R & lt spaces or removing the specified symbol on the right 
Print (str4.lstrio ())
 Print (str5.rstrip ()) 
str4 =' *** My name XXX IS, IS My Age 18. A ' 
str5 = ' My name XXX IS, IS 18 is My Age. *** ' 
Print (str4.lstrio ( ' * ' ))
 Print (str5.rstrip ( ' * ' )) 


# the format 
# accordance with alternative position 
# accordance Alternatively it 
# by name replaced (by name) 
STR7 = ' My name IS {name}, {My Age Age IS} ' 
STR7 = str7.format (name = ' ZCJ ' , Age = 18 is )
 Print (STR7) 

Str8 = 'IS {name}. 1 My, My 2 Age {IS} ' 
Str8 = str8.format ( ' ZCJ ' , 18 is, 21 is )
 Print (Str8) 

# the Join to the string concatenation, will identify the data list according to some splicing 
name = ' ZCJ ' 
Age = ' 18 is ' 
Print ( ' : ' .join ([name, Age])) 

# Split, rsplit: cut open from the left, from the right cut 

# Replace: parentheses first parameter is old parameter the second is a new parameter, an amount of parameter substitution 
Str8 = ' Old new new ' 
Str8 = str8.replace ( ' Old ' , 'python')
 Print (Str8) 

# isdigit: determining whether the numeric string 
# ID = INPUT ( "Please enter:") 
# Print (type (ID)) 
# Print (ID.isdigit ())
 
# Built list method 
# 1 by index values, forward from the left, from the right negative 
List = [ ' ZCJ ' , 18 is, ' FEMALE ' , 3.0,. 9 ]
 Print (List [. 4 ])
 Print (List [ -2 ]) 

# slicing, care regardless tail, step (5-1) 

Print (List [. 1:. 5 ])
 Print (List [. 1:. 5: 2 ]) 

# length len 
Print (len (List)) 

# and in operation in members not 
Print ( ' ZCJ '  in List)
 Print ( ' ZCJ '  not  inList) 

# additionally 
# list append value 
list.append ( ' HHH ' )
 Print (List) 

# POP Remove 
# POP values extracted list 
# Remove delete the value list 
Print (list.pop ())   # default - . 1 
Print (List)
 Print (list.pop (0))   # ZCJ 
Level = list.pop ()
 Print (List) 

# name = list.remove ( 'ZCJ') 
# Print (name) 
# Print (List)

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/-zcj/p/11005605.html