Second week - 11 common operating string section -Python3.5-

PCJ # 
name = "xiaoming"
# capitalize ()
# String.capitalize () to capitalize the first letter of a string
print (name.capitalize ()) # capitalized
# COUNT ()
# String.count () appear statistical character the number of
print (name.count ( "i") ) # statistics i have a few letters

# Center ()
# String.center () print out the character, so the string in the middle of
print (name.center (50, "- "))


# endsWith ()
# String.endswith () determines whether the end of the string specified
print (name.endswith (" ing ") ) # determines whether to end ing.

The Find # ()
# string.find () to find the string in the original string, where the return index
print (name.find ( "g") ) # Find g letter subscript

# format ()
# String.format ( ) specified content output
user_show_name = "Hello, {name}, whelcome to here Wallpaper"
Print (user_show_name.format (name = "PCJ"

Whether # String.isalnum () determines a string all numbers or English
print ( "111a" .isalnum () ) # and returns the value true or flase

# the isalpha ()
determines string # String.isalpha () whether all plain English characters
print ( "abcd" .isalpha () ) # letter together only for the True

# isdigit ()
# String.isdigit () to determine whether a string of all integers
print ( "123" .isdigit () ) # full digital only return True

# isIdentifier ()
# String.isidentifier () judgment is not a valid identifier
print ( "pcj" .isidentifier () ) # can be understood as whether a valid variable name

# judge whether all strings uppercase and lowercase
print ( "pcj" .islower () ) #islower lowercase
print ( "PCJ" .isupper () ) #isupper uppercase

# the Join ()
# sep.join (SEQ) connected to an array of strings. A string, a tuple, in the list element to specify character (separator) connected to generate a new string

names = [ "Jacky", "Andy", "Aaron", "Dawn"]
Print ( "- ---. "


# String.ljust (size, replacement symbols) counted from front to back, when the size exceeds the length of the string, the excess replaced by replacement symbols
Print ( "PCJ" .ljust (50, "-"))

# the rjust ()
# String.rjust (size, replacement symbols) calculated from the back to front, when the size exceeds the length of the string, the excess replaced by replacement symbols
Print ( "PCJ" .rjust (50, "-"))

# the Lower string uppercase to lowercase
# upper string lowercase capitalized
Print ( "PCJ" .upper ())
Print ( "PCJ" .lower ())

# lstrip remove the string of spaces left or Enter
# rstrip remove characters string to the left of the space or Enter
# strip method. Remove the left and right sides of the carriage return or space

print ( "pcj left spaces" .lstrip ())
print ( "pcj the right spaces" .rstrip ())
Print ( "space on both sides" .strip ())

# replace the replace
print ( "pcj" .replace ( " p", "P")) # p replace the lowercase to uppercase P

# Split
# the String.split () cut
print ( "

Guess you like

Origin www.cnblogs.com/pcjbk/p/10958844.html