3. string functions to achieve

# ################## 1. Upper / lower usage simple ################### 
'' '
value = 'Alex SB'
Print (value)

value = 'Alex SB'
NEW_VALUE = value.upper ()
Print (NEW_VALUE)
'' '
' '' does not change the value of the value, will generate a new value
must be newly generated later the value assigned to accepting a new variable '' '


' ''
value = 'Alex SB'
NEW_VALUE = value.lower ()
Print (NEW_VALUE)
'' '


# ###### exemplary codes
# cumbersome EDITION
' ''
= check_code 'iyUF'
Message = 'Please enter PIN% s:'% (check_code, ) # formatting character
code = iNPUT (Message)
new_check_code = check_code.lower ()
new_code = code.lower ()
IF new_check_code == new_code :
print ( 'successful landing!')
'' '

# simple version of
' ''
= check_code 'iyUF'
code = INPUT ( "Please enter the verification code S%: '% (check_code,))
IF code.lower () == check_code.lower (): # direct comparison
print (' successful login! ')
'' '

# ################## 2.isdigit simple use ###################

Print (' ' 'Please call 10086
1. Charge services
2. traffic service
3. broadband' '')
-service = iNPUT ( 'select service:')
Judge = service.isdigit ()
# determines whether the user input string can be converted to digital. # '666' 'Chi Master'
Print (Judge) # Boolean value
IF Judge:
-Service = int (-Service)
Print (-Service)
the else:
Print ( "Enter a number")



# ########### . ####### removing the blank 3 Strip / the lstrip / ################# The rstrip
'' '= user iNPUT (' enter username: ') #'

new_user2 = user.lstrip () # remove spaces left
new_user3 = user.strip () # remove clear space Note: You can not delete an intermediate portion
Print ( '->', User, '<-')
Print (new_user1)
Print ( new_user2)
Print (new_user3)
'' '

# ##############. 4. Alternatively ##################### replace
' ''
the Message = the INPUT ( 'please speak:')
Print (the Message) # I went to your uncle home to play
content = message.replace ( 'your uncle', '***') # your uncle will be replaced by '*** '
Content = message.replace (' your uncle ',' *** ', 1) # From left to right number, you need to replace several
Print (Content)
' ''


# ########### ### 5 cutting Split / rsplit #####################
'' '
the Message =' Zhang is now forced to look ignorant, because he had slept well, over and over again. '
Incision message.split = (', ' ) # Cut in accordance with a comma.
incision1 = message.split ( ',', 1) # number from left to right to locate the first comma cutting.
incision2 = message.rsplit ( ',') # right to left, cut in accordance with a comma.
incision3 = message.rsplit ( ',', 1) # right to left, the first to find a comma cutting.

Print (incision)
Print (incision1)
Print (incision2)
Print (incision3)

# Note: Returns the value list after dividing
'' '

Guess you like

Origin www.cnblogs.com/zyg-ayy/p/11070558.html