Primitive string Operators
(1) Primitive string operators are designed to deal with special characters that appear in a string
(2) in the original string, all characters are used directly in the literal sense, and no special or non-printable characters are escaped.
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/84/91/wKiom1eVdW7B6a0yAAAU9pDOywI769.png "title=" Sogou 20160725101139.png "alt=" Wkiom1evdw7b6a0yaaau9pdoywi769.png "/>
(3) For example, when Windows writes a path, the following conditions are often
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/84/91/wKioL1eVdm6AbaPLAAA43XLbeAQ095.png "title=" Sogou 20160725101556.png "alt=" Wkiol1evdm6abaplaaa43xlbeaq095.png "/>
2. String built-in functions
(1) The original value of the string is not changed each time
(2) String. Function or assign a string to a function and write a variable name. functions are all possible.
(3) There are a lot of connotation functions, below is just an example to illustrate
>>> Import Tab
>>> hi = "I love You"
>>> hi.capitalize ()
' I Love You '
>>> Hi.rjust (30)
' I love you '
>>> Hi.ljust (30)
' I love you '
>>> Hi.center (30)
' I love you '
>>> Hi.center (30, "+")
' ++++++++++i Love you++++++++++ '
>>> Hi.count ("I")
1
>>> Hi.count ("I", 6)
0
>>> Hi.endswith ("U")
True
>>> Hi.startswith ("U")
False
>>> Hi.islower ()
True
>>> "zhang123". Islower ()
True
>>> Hi.isupper ()
False
>>> Hi.upper ()
' I Love You '
>>> Hi.lower ()
' I love you '
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/84/92/wKioL1eVfkOTVJSkAACPZO7E85k453.png "title=" Sogou 20160725104821.png "alt=" Wkiol1evfkotvjskaacpzo7e85k453.png "/>
>>> astr = "I love you \ t \ n"
>>> Astr.strip ()
' I love you '
>>> Astr.lstrip ()
' I love you \ t \ n '
>>> Astr.rstrip ()
' I love you '
>>> Astr.rstrip ("You")
' I love you \ t \ n '
>>> Astr.rstrip ("\n\tyou")
' I love '
>>> Astr.strip ("You")
' I love you \ t \ n '
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/84/93/wKioL1eVgfqCoF64AABCCK6Fq0Q105.png "title=" Sogou 20160725110444.png "alt=" Wkiol1evgfqcof64aabcck6fq0q105.png "/>
>>> Hi.split ()
[' I ', ' love ', ' You ']
>>> "home.tar.gz". Split (".")
[' Home ', ' tar ', ' GZ ']
>>> astr = "" "I
... love
... you "" ""
>>> Astr.split ()
[' I ', ' love ', ' You ']
>>> Astr.splitlines ()
[' I ', ' love ', ' You ']
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/84/93/wKiom1eVhDaAjZS9AAAyYRh9u3k135.png "title=" Sogou 20160725111256.png "alt=" Wkiom1evhdaajzs9aaayyrh9u3k135.png "/>
>>> hi.replace ("I", "You")
' You love '
>>> hi.replace ("O", "AAA", 1)
' I laaave you '
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/84/93/wKioL1eVh2LzcG_BAAAVA0VEhEs823.png "title=" Sogou 20160725112818.png "alt=" Wkiol1evh2lzcg_baaava0vehes823.png "/>
This article is from the "Court of the Odd Tree" blog, please be sure to keep this source http://zhangdl.blog.51cto.com/11050780/1829568
Learn to write: Python primitive string operator && string built-in function