String: quoted by the wrap
Null character: there is no character
blank character: there are content, content is the spacebar
python is any data can be converted to a Boolean value
print (bool (s1)) # s1 no content data, is converted to a boolean value False
Print (BOOL (s2)) # s2 in the content data, is converted to a Boolean True
Numeric type into a string
STR = S3 (num_5)
Print (type (S3), S3)
- by str () function, the value type can be converted to a string
String Manipulation
--- index value can be positive sequence values, the values may be reverse; positive sequence index value starting from 0, descending the index value starting from -1;
EG: STR = 'Hello Python' n ----- sequence index: res1 = str [0]; inverted index: res2 = str [-1]--- slice taken out of the string value or - String
2.1 str [m: n] --- m is the start index, n + 1 is the ending index, taking the end of the head does not take
2.2 str [: n] - - writing start position is not the default scratch
2.3 str [m:] --- not write end position, the default end
2.4 str [m: n: k ] --- is step by step sections, k, is take a number
String concatenation
3.1 + Number splicing EG: STR = str2 str1 +
3.2 The method of the Join string x.join ((string1, string2 2)) eg:. Str3 = ',' join ((str, str1)), join which is a parameter, so the composition of a string to be connected into the tuple list orString escape
\ n: newline \ t: tab r: content can force the output of all strings, without escaping
Based approach of the string
Find elements
str.find ( "a", m) ---- a is an element you want to find, the value of m is an element m from the index to start looking; m not write anything, the index value from 0 position to start looking
(), The number of statistical elements appear in the string count
replace (), the replacement string element
Split (), cutting strings, after cutting returns a list of types of data
String case conversion, upper () / lower ()
Formatted output string
- formatted output format
- Traditional conventional format output format output ----%% s% d% f
- F expression (the new version is available, expand knowledge)
decimal format specified output: {:. 2f} - Specifies the output 2 decimals