Use string python_

= hw 'the Hello World \ tk ...' 
HW2 = 'the Hello World \ t {k} ... {look}'
# capitalized
Print (hw.capitalize ())
#hello world k ...
# character statistics the number of strings in the
Print (hw.count ( 'O'))
# 2
# 50 characters printed, not on both sides with - filling
Print (hw.center (50, '-'))
# -------- k ...----------------- the Hello World ---------
# converted to binary
Print (hw.encode ())
# b'Hello World \ ... tk '
# determine what string to the end
Print (hw.endswith ('. '))
# is No True False
# the \ t converted to the number of spaces
Print (hw.expandtabs (TabSize = 20))
#hello K ... world
# search string position
Print (hw.find ( 'world'))
#. 6
Print (HW [. 6:])
#World K ...
# alternative format change and
Print (hw2.format (= K 'Ken', = look 'pppp'))
#hello World Ken ... pppp
# dictionary usage
print (hw2.format_map ({ 'k' : 'ken', 'look' : 'pppp'}))
#hello World Ken ... pppp
# Find character position
Print (hw.index ( 'O'))
#. 4
# determines whether or not the character string or digital
print ( 'ASrdw ... 10993'.isalnum ())
#False
Print ( 'ASrdw10993'.isalnum ())
#True
# determines whether the English character string
Print (' Adfooi'.isalpha ())
#True
Print ( 'Adfooi002'.isalpha ( ))
#False
# determines whether a decimal string
print ( '55121'.isdecimal ())
#True
print (' 5A'.isdecimal ())
#False
# determines whether the character string is an integer of
print ( '1558'.isdigit ()) # often used
#True
Print ( '1.1558'.isdigit ())
#False
# determines whether the string is valid identifier
Print (' auia'.isidentifier ())
#True
Print ( '2auia'.isidentifier ())
#False
# determines that the string is a lowercase
Print ( 'aadc'.islower ())
#True
Print (' aAdc'.islower ())
# False
# determines whether the string is a digital
print ( '3A'.isnumeric ()) #str type of digital
# fale
Print ( '300234'.isnumeric ())
#True
# determines whether or not a space character string
Print (' 3A'.isspace ())
#False
Print ( '' .isspace ())
#True
# determines each header string It is an uppercase letter
Print ( 'the Hello World'.istitle ())
#True
Print (' the Hello World '.istitle())
#False
# Determines whether the print string, general tty file, drive file can not be printed
Print ( 'the Hello world'.isprintable ())
# determining whether a string to uppercase
Print (' the Hello world'.isupper ())
#False
Print ( ' WORLD'.isupper HELLO ())
# transferred out of the list of strings, and can customize the blocking character
print ( '=='. join ( [ 'a', 'b', 'c'])) # often to
# == A == B C
Print ( ''. the Join ([ 'A', 'B', 'C']))
#abc
# Right filled
print ( 'HELLO WORLD'.ljust (50, ' ~ '))
#hello WORLD ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# left padded
print ( 'HELLO WORLD'.rjust (50,' ~ '))
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HELLO WORLD ~~~~~~
# uppercase to lowercase
print ( 'HELLO WORLD'.Lower ())
#hello World
# lowercase capitalized
Print ( 'Hello world'.upper ())
#hello WORLD
# Default used to remove the beginning character, blank character (including \ n, \ r, \ t , '', namely: line feed, carriage returns, tabs, spaces)
Print ( '\ tHello world'.lstrip ()) # often used
#hello World
Print ( 'Hello world'.lstrip (' H '))
#ello World
# end to remove the default character, blank character (including \ n, \ r, \ t ,' ', namely: line feed , carriage returns, tabs, spaces)
Print ( 'Hello World \ t'.rstrip ()) # frequently used
#hello World
# character is used to remove the head and tail, the blank character (including \ n, \ r, \ t , '', namely: line feed, carriage returns, tabs, spaces)
Print ( '\ tthllo World \ t'.strip ()) # frequently used
#hello World
# character conversion, conversion of the characters of the
list str.maketrans = ( 'abcdef', '123456')
Print ( 'Hello world'.translate (List))
# h5llo worl4
# replacement string content
print (' hello world'.replace ( 'l ', 'L')) # Frequently used
#hello WORLD
Print ( 'Hello world'.replace (' L ',' L ',. 1))
#hello World
# Find the right value
Print ( 'Hello world'.rfind (' L '))
#. 9
# string into a list, by default to distinguish spaces
Print (' Hello world'.split ())
# [ 'Hello ',' World ']
Print ('. 3. 1 + 2 + + + 5'.split. 4 ( '+'))
# [ '. 1', '2', '. 3', '. 4', '. 5']
# string into a list, to distinguish the transport default
Print ( '. 1 \ N2 \ N3 \ N4 \ n5'.splitlines ())
# ['. 1 ',' 2 ','. 3 ','. 4 ',' 5 ']
# uppercase to lowercase, uppercase becomes lowercase
Print (' the Hello World'.swapcase ())
#hello WORLD
# first character of each variable capital
Print ( 'the Hello world'.title ())
#hello World
#
Print (' world'.zfill the Hello (50))
# 000000000000000000000000000000000000000hello world

Guess you like

Origin www.cnblogs.com/wxy1987/p/11007379.html