And partially formatted string operations

Its operation partially formatted string # 
I =. 3 
STR = "FGdV" 
the while I> 0: 
    I = I. 1- 
    user_input = INPUT ( "Please Enter Security code:") 
    IF str.upper () == user_input. Upper (): 
           Print ( "the Input Success") 
           BREAK 
    the else: 
           Print ( "Please the Enter Again:") 

    Print ( "by You have have% d More Chances"% (i)) 
Print ( "Game over") 

# this method is to let verification code entered by the user are capitalized to match, if verified that 
# capitalization of matching uppercase, lowercase matching lowercase how should we do it, the case of letters of the digital operation is not affected oh 



# string operation 
#capitalize capitalized character string of 
a = "Hello Linda" 
B = a.capitalize () # the Hello Linda original string will uppercase lowercase 
Print (B) 


B1 = a.Upper () 
Print (B1) #hello LINDA Upper string all uppercase

b2 = a.lower () # hello linda lowercase string Full 
Print (B2) 

# Use string: code verification is not case sensitive, you determine how code is correct 
I =. 3 
the while I> 0: 
    I = . 1-I 
    STR = "hvhGH" 
    user_input = INPUT ( "Please Enter Security code:") 
    IF str.upper () == user_input.upper (): 
        Print ( "successfully Login") 
        BREAK 
    the else: 
        Print ( "Please Enter Again ") 
        Print (" you only have have% d Chance "% (i)) 
Print (" Your Chance iS up ") 

# the original verification code entered by the user code are converted to a standard, so that users can enter up to three times 


b3 = a.swapcase () # string in lowercase uppercase, lowercase to uppercase side 
Print (B3) #hello Linda swapcase 

'' ' 

' '' 
B = "are at The Timeless memony in you My Heart " 
b1 = b.title () # to capitalize the first letter of the string
Print (B1) of The Timeless Memony the In #You Are My Heart title 


C = "you are in my56heart the6timeless memony" 
B2 = c.title () 
Print (B2) 

C1 = "you are in my56he Mony the6timeless Me # $ Art" 
B3 = c1.title () # of course, the title will be separated by special characters or numbers words capitalized 
Print (b3) #You are The6Timeless Me Art # Mony an in My56He $ 

b = "you are at the Timeless memony in My Heart " 
B1 = b.center (80) #center (can fill digital) for centering str, str this embodiment is that the intermediate position is located 80 
Print (B1) # the Timeless memony you are in My Heart   


a =" HelloWorld Hello " 
A1 = a.startswith (" of He ") # for determining whether the character string in brackets start 
print (a1) #true results 

a2 = a.startswith (" l ", 3,6) # l character determination 2 and is in position 5 of the string to 
Print (A2) 

'' ' 
' ''
a="helloworld hello"
a.find = a3 ( "w") 
A4 = a.find ( "k") 
Print (a3) # 5 
Print (A4) # - 1 
#find find character, returns the index of the character, returns can not be found - 1 
a5 = a.find ( "WO") 
a6 = a.find ( "GH") 
Print (a5) # 5 
Print (a6) # - 1 
# If you are looking for more characters, where the first character returned index, if not found, returns -1 

A7 a.index = ( "L") 
# A8 = a.index ( "m") 
Print (A7) # returns the index of the character look less than a given 
#print (a8 ) 


name = the iNPUT ( "Please the enter your name:.") strip () 
IF name == "Linda": 
    Print ( "the Hello Linda") 
the else: 
    Print ( "name IS error") 

# add a strip even then enter your name when, by mistake entered a space also can not go wrong, space before and after strip default deletion 
#lstrip () to delete the left side of the space, rstrip () to remove spaces to the right of 


d = "IloveChina the I Love china LOVE" 
d1 = d.count ( "o") # number of the letter string o how many 
print (d1) # 2

d2 = d.split ( "o") # accordance split rule you wrote, the string into a list 
the I AM Linda, Age IS 18 is, the I AM Linda
d3=d.split(" ")#被分割的元素就不存在了
print(d2)#['Il', 'veChina I l', 've china LOVE']
print(d3)#['IloveChina', 'I', 'love', 'china', 'LOVE']

'''
'''
s="I am {},age is {},I am {}".format("Linda",18,"Linda")
print(s)                                      

s1="I am {0},age is {1},I am {0}".format("Linda",18)
print(s1)

s2="I am {name},age is {age},I am {name}".format(name="Linda",age=18)
print(s2)
s3=s.replace("Linda","Chichy")#把Linda替换成Chichy
s4=s.replace("Linda","Chichy",1) # digital 1 replaces only once 
the I AM Chichy, Age IS 18 is, the I AM Chichy
the I AM Linda, Age IS 18 is, the I AM Linda
the I AM Linda, Age IS 18 is, the I AM Linda
Print (S4)
Print (S3)





I am Chichy,age is 18,I am Linda

f="Hello Linda,Welcome to China"
if "Linda" in f:
    print("Welcome to China")
else:
    print("Linda not exist")
#Welcome to China

'''

  

Guess you like

Origin www.cnblogs.com/GZ1215-228513-Chichy/p/11260429.html