python built-in types mainly includes seven major categories:
- digital
- sequence
- Mapping
- file
- class
- Examples
Abnormal
wherein the data type is the most common sequencesequence
Built-in python sequence containing 7
- List (list): constituted by square brackets separated by commas items: [a, b, c]
- Tuple (tuple): tuple comma operator configured (not in brackets), the brackets must be empty tuple brackets, eg: (d,) ()
- String (str): single or double quotes written, eg: "abc", 'abc'
- unicode string (unicode): str with similar, but designated by u before use, eg: u "abc", u'abc '
- Byte array (bytearray): Use the built-bytearray () function to create an object Bytearray
- buffer objects (buffer): created by calling the built-in function buffer (). They do not support connections or repeat
xrange objects (xrange): Use xrange () function created. They do not support sections, connections or repeat
General Operation Sequence
operating result Explanation x in s True or False Determine whether x is a member of s s + t st s and t are connected s * n , n * s sequence S new sequence consisting of a sequence of n s[i] An element An element access sequence s s[i:j] Range of elements S access to the range of elements in the sequence s[i:j:k] Range of elements S access sequence steps within a range of k elements only (a) Numerical Length sequence s min (s) Numerical Minimum sequence s max(s) Numerical The maximum value of the sequence s s.index(x) Numerical Access location index x occurring sequence s s.count(x) Numerical X s in the number of elements in the sequence of occurrence
Common methods string
> 1.str.capitalize() #返回字符串副本,第一个字母大写,其余小写
> 2.str.count(sub) #返回sub字符出现的次数
> 3.str.encode()/str.deconde() #编码/解码
> 4.str.find() #返回某元素第一次出现的索引
> 5.str.format() #格式化字符串
> 6.str.join(seq) #指定字符串连接
eg:
str = "-";
seq = ("a", "b", "c");
print str.join(seq);
a-b-c
> 7.str.lower() #所有包含字符转化为小写
> 8.str.replace(old,new) #字符替换
> 9.str.split(' ') #通过指定字符串切片
>10.str.startswith(sub)/str.endwith(sub) #检查是否以sub开始/结束
>11.str.strip(sub) #移除字符串头尾指定的字符序列