Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

1. Introduction to python strings and common functions


May 10, 2021 Python2


Table of contents


1. Introduction to strings in python and common functions

In python, a string becomes a powerful set of processing tools, and he is imm changed, that is, the string contains the order of characters and characters, which he cannot modify in place

Strings are the slightly larger categories of objects that we need to learn later -- the first representation of the sequence

The following list applies to the operation of the sequence as much as the metagroup, as described in the string section

Some of the operations and functions commonly used by strings

Operation Explain
s='' An empty string
s="abc'd" Double quotes are the same as single quotes
s='abc\n' Escape sequence, using variables to display characters completely, only using the print function can display escape
s="""aaaaa""" Triple quote string block
s=r'\temp\spam' Raw string
s=b'abc' The byte string of python 3.x
s=u'bac' Unicode string
s1+s2 Merge
s*3 Repeat
s[i] Index
s[i:j] Sharding
len(s) Find the length
“a %s parrot” % kind The string formats the expression
"a {0} parrot".format(kind) The string formatting method
s.find('xxx') Search
s.rstrip() Remove spaces
s.replace('xxx','xxx') Replace
s.endswith('xxx') Ends with xxx
'xxx'.join(strlist) Access separator
s.encode('latin-1') Change the code
for x in s:print(x) Iteration
‘xxx’ in s Membership
[c*2 for c in s] Membership
map(ord,s) Membership