Coding
1. The earliest ascii:8 bit, 1 bytes (8bit=1byte), the most basic, 128 code bit
2.GBK GB Code: 16-bit, 2-byte
3.unicode Universal Code: 16-bit, 2-byte
Utf-8: English 8bit 1 bytes; Euro 16bit 2 bytes; medium 24bit 3 bytes
Overview of basic data types
1. int integer binary length: Bit_length ()
2. STR string stores a small amount of data
3. BOOL Boolean True 1 False 0
s = "" # empty things are false, non-empty are true
m = None #None is empty, is false
4. The list table saves a large amount of data, you can change the remove
4.1 Indexes and slices
The index is the subscript, from left to right, starting from 0. From right to left is starting from-1.
s = "I love Jay Chou's daughter-in-law"
Print (s[0]) #我
Print (s[-1]) #妇The content obtained through the index or a str
Slices can intercept the string str
#语法s[start position: End position: Step]
s = ' Alex and Wusir often together '
Print (S[2:5]) #ex和 features:"Gu Tou regardless of the tail"
S2 = s[:] #从头到尾切出来
S3 = s[-3:] #切出后3 default from left to right
S4 = S[6:2:-2] #-represents the opposite, each of 2 take one
4.2 Common methods for strings
. Capitalize () capitalize first letter
. Upper () all uppercase
. Lower () all lowercase
. Center () makes the center
Che cut away
s = input (' User name '). Strip () #去掉左右两边空格 can also remove \ t
. Lstrip () Remove the left space. Rstrip () go to the right space
S. Replace (' A ', ' B ') #用b替换a
SS = S.replace (', ') #去掉所有空格
S. Split (') # ' is the knife, the finished item is a list, the list is a str
s = ' A_w_t_b '
LST = S.split ('_') #_是刀
Print (LST) #[a,w,t,b]
Formatted output
s = ' I call {1}, I am {0} years old this year, I like {2} '. Format (' Sylar ', ' + ', ' yy ')
Print (s) #我叫18, I Sylar year old, I like YY
s = ' My name is {name}, my age {"} '. Format (name = ' Lee ', ages = ' + ') #S.format () You can specify a location, or you can specify a parameter
Print (s) #我叫lee, my age 30
Find
s = "Wang Feng's wife doesn't love Wang Feng"
S.startswith (' Wang Feng ') #判断字符串是否以 ... Beginning
S.endswith (") # End
S. Count (') #判断 ... The number of occurrences in the string
S. Find (') #计算 ... The index position that appears in the string, if it does not appear, returns-1
S.find (' Wang Feng ',3) #7
S.index () #index中内容如果不存在, direct error
S.isdigit () #判断是否由数字组成
S.alpha # Letters
S.alnum # Numbers and letters
Calculating string Lengths
s = ' Have you had a drink today? '
i = Len (s) #python的内置函数
i = S._len_ () #也可求长度, the Len () function executes when it is actually executed.
Using the While loop string
Count = 0
While Count < Len (s):
Print (S[count])
Count + = 1
To iterate through a string with a for loop
For C in S: #把s中每一个字符交给前面的for循环
Print (c) #优势: Simple disadvantage: No index
5. Tuple tuples save large amounts of data, read-only cannot be changed
6. Dict dictionary a pair of storage key:value
7. Set collection does not duplicate the content
Python coding and several simple data types (INT,BOOL,STR)