python basis of Chapter VII of the string

String

String definition: double quotes may be coated single quotation marks, double quotes single quotes may be coated,

      Double quotes and single quotation marks double bag package need double quotes '\\'

str1 = 'Hello \' world \ '' (note position) 
Print (str1)

escapes classification:
\: life character
str = 'Hello \ 
World \
la la la'
Print (str)

\ N: line breaks
str = 'Hello \ n Hello' 
Print (STR)

\ R: only output \ r behind the content
str = 'good today \ r hot ah' 
Print (str)
Separated by a table between two characters make: \ t
str = 'good today \ t hot ah' 
Print (str)
\ B: backspace
str = 'good today \ b hot ah' 
Print (str)
\\: backslash output
str = '\\ good hot today ah' 
Print (str)

r: transfer character is output
str = r 'Today \ n days good \ t hot \ b ah' 
Print (STR)

string concatenation: +
string copying operation: *
string index calculation: []
slicing the container
vessel [start value: End Found: jump value] (left and right open and close timing sequence starting at 0, starting from the flashback -1)
jump if the value of the write will not skip default value is 1
str = 'Hello world I am very happy' 
RES = str [0: 4: 1]
Print (RES)
str = 'Hello world I am very happy' 
RES = str [-1: -4: -1]
Print (RES)

string-related functions:
the English related to:
Upper (): all lowercase letters to uppercase
lower ( ): converts all uppercase letters to lowercase
swapcase (): invert case
title (): the string of letters carried the title treatment (the first letter of each word is capitalized, the rest lowercase)
capitalize (): first a letter should be capitalized, the rest are lowercase
Format 
STR = 'asdaDAD'
RES = str.upper ()
Print (RES)
String index-related functions: 
index (the character you are looking for, start index, end index): from left to right to find, can not find the error
rindex (character you are looking for, start index, end index): the right to I do find, can not find the error
find (the character you are looking for, start index, end index): from left to right to find, can not find the output -1 
rfind (character you are looking for, start index, end index): the right to do to find, find less than outputs -1
Format 
str = 'devil do you do you devil'
RES = str.index ( 'do', 0,10)
Print (RES)
:( determine the correlation function string output is True or False) 
isupper (): Check whether all capital letters
islower (): Check whether all lowercase
istitle (): Check that each word is capitalized
isalnum () : check for numbers, letters, text composition
isalpha (): check whether a picture and text composition
isdigit (): check whether the decimal character
isnumberic (): check whether the numbers
isspace (): check whether the blank characters
startswith (): checks a string beginning with the specified character string
endswith (): check whether the specified string end of the string
Format 
STR = '12wqswqs'
RES = str.isupper ()
Print (RES)
Related string manipulation functions: 
Split (cleaved using characters, the number of cuts)
'character' .join (): use the character string to connect together
zfill (length of the entire string); 0 filling effect, if the length of the string enough do not filled, or filled with zeros
Center (true string length, filled symbols): original data center aligned on both sides is filled with fill symbols
ljust (): the contents of the original left, right filled with fill symbols
the rjust (): original SUMMARY right-justified, sign left filled with a filling
strip (): removal of both sides of the specified continuation character
lstrip (): removing the left specified continuation character
rstrip (): removing the right specified continuation character
replace (): the replacement string
count () : statistical number of occurrences of the specified character string

string formatting operation;
Percent formatting operation:
% D: formatting an integer
% s: a formatted string
% f: formatting a float
% 5f : decimal defined as 5
str = 'Bob today spent membered% d,% s he is angry'% (100, 'father') 
Print (STR)

the format format operation
basic format:
variable .format (parameter, parameter ......)
parameter passing Classification :
order of parameter passing, the index (position parameter passing), the keyword parameter passing, container type transmission parameters (the index value), parameter passing dictionary
Parameter passing sequence 
str = 'graceful sent: {}, Unconstrained: {}, pie: {}'. Format ( 'Qingzhao', 'ji', 'Daly Park')
Print (STR)

position parameter passing
str = 'graceful sent: {2}, Unconstrained: {1}, pie: {0}'. format ( ' Daly Park', 'ji', 'Qingzhao') 
Print (STR)

keyword parameter passing
str = '{god} say: believe in me eternal life, {zengge} also said' .format (god = 'God', zengge = 'have brother') 
Print (STR)
container transfer parameters (the index value)
str = '{0 [0] } , said: believe in me eternal life, {1 [0]} also said' .format ([ 'God', 'the fields', 'in the'], ( 'have brother' , 'into Columbia')) 
Print (STR)

dictionary parameter passing
dict1 = { 'Simon': "Venus"} 
str = '{} said: you respect my foot, I have you ten feet' .format (dict1 [ 'Simon'])
Print (str)

Alignment (optional position, fill symbols Alternatively, the total length optional)
<Left
> right justified
^ centered
parameter position: the total length of the fill symbol alignment symbology
str = '{0 [1] : * <6} say: you respect my foot, you ten feet I' .format ( 'sister Venus', 'Silver Star sister') 
Print (STR)

output: Star ***** said: you respect my foot, I have you ten feet

accuracy limit:
: .2f means that accuracy is limited to a double-digit

financial symbols:
:, represent numbers from right to left, plus a three per comma



Guess you like

Origin www.cnblogs.com/szc-boke/p/11238485.html