String method often used python

= spam 'the Hello world'
Print (spam.upper ()) # all converted to uppercase letters, characters turn Africa alphabetic characters remain the same
print (spam) # original string spam has not changed
spam2 = 'HELLO WORLD'
Print (spam.lower ()) # all converted into lowercase letters
# above two methods does not change the string itself but returns a new string
spam3 = 'the Hello World'
# string if there is at least one letter, and all the letters are lowercase, returns True, otherwise it returns False
Print (spam3.islower ())
# string if there is at least one letter, and all letters are capitalized, will return True, otherwise it returns False
spam4 = ' WORLD HELLO '
Print (spam4.isupper ())
#isalpha () returns True, and if the letter string contains only non-empty
Print (spam4.isalpha ())
#isalnum () returns Ture, if the string contains only letters and numbers , and non-empty
spam5 = 'of hello2'
Print (spam5.isalnum ())
# isdecimal () returns True, if string contains only numeric characters, and non-empty;
# isspace becomes () returns True, if the string only contains spaces, tabs and line feed, and non-empty;
# istitle () returns True, if the string contains only begin with a capital letter followed by lowercase letters of the word.
# Enter the following code in an interactive environment

Guess you like

Origin www.cnblogs.com/shunguo/p/11441644.html