str (string)
* 定义: s = " " s = str( )
* capitalize() 首字母大写
* title() 每个单词的首字母大写
* count() 统计
* swapcase() 大小写转换
* find() 从左到右查找元素,返回元素的索引值,找不到返回-1(推荐使用)
* index() 查找元素索引 找不到会报错
list (list)
* 定义: li = [ ] li = list( )
* count() 统计
* 注意: 列表中没有count()
* index() 查找元素索引
* reverse() 反转列表
* sort() 排序 默认升序, li.sort(reverse = True) 降序
tuple (tuple)
* 定义: tu = ( ) tu = tuple( )
* count() 统计
* 元组没有 find()
* index() 查找
dict (dictionary)
Is defined: dic = {} dic = dict (k = 1, k1 = 2)
dic.popitem () random delete the default version Python3.6 delete the last pair
dict.fromkeys ( "123", 1) to quickly create a dictionary (not recommended)
The first element is an object iteration, the second element corresponds to the value of each is a bond, is common to the same memory address, if the stored data type is variable, then post-processing will be very troublesome
set (collection)
* 定义: s = {"s"} s = set("1234")
Data type conversion
Int type string into the string are decimal numbers must
str→list split()
list → str join () join can not digital
In addition to the dictionary, the data type between the containers can be interchangeable
So for loop by deleting the list element when deleted from left to right will complain, will not produce results
Can be removed by way of a reverse circulation
List and then add elements cycle itself will cause an infinite loop
Dictionary can not traverse their cycle operation can not change the size of the loop itself
You can create a list to be deleted key is stored in the list, and then delete the key to achieve the circulation list for the purpose of
Advanced coding
ascii does not support Chinese
gbk GB Chinese English 2 bytes 1 byte
unicode Unicode byte Chinese English 2 4 bytes
utf-8 English 11 bytes Asia Europe 2 bytes 3 bytes
Byte is stored in the hard disk is transferred byte
- encode ( "encoding format") encoding a string into a byte i.e.
- decode ( "encoding format") into a string of bytes that is decoded
- Principle: What is the format used to encode decode what format
- Python3 in memory usage is unicode
- Python2 in memory using ascii