1. Common data types
1). digital int float LONG
2). Boolean True False
3). String
4). List
5). Tuples
6). Dictionary
2, Strip () # #去掉字符串前后的空格
3. Split () # #按空格切割字符串
4.Insert() # #向列表中插入元素
Insert a new element in the 2nd position of the name list:
>>> name = [' Jim ', ' Kek ', ' Alex ', ' Wusir ']
>>> Name.insert (2, ' Eric ')
>>> Name
[' Jim ', ' Kek ', ' Eric ', ' Alex ', ' Wusir ']
>>>
5. Count the number of specified elements in a list:
>>> Name
[' Jim ', ' Kek ', ' Alex ', ' Wusir ', ' Jim ']
>>> Name.count (' Jim ')
2
>>>
6. Delete the last element in the list
>>> Name
[' Jim ', ' Kek ', ' Alex ', ' Wusir ', ' Jim ']
>>> name.pop ()
' Jim '
>>> Name
[' Jim ', ' Kek ', ' Alex ', ' Wusir ']
>>>
7. Sorting in the list
>>> Name
[' Jim ', ' Kek ', ' Alex ', ' Wusir ', ' 89 ', ' 28 ']
>>> name.sort ()
>>> Name
[' Up ', ' kek ', ' Alex ', ' Jim ', ' Wusir ', '
>>>
When the list of elements with numbers and letters is combined, sort the numbers in ascending order, and then install the letters in sequence!
8, according to the number of repetitions of the specified element in the list n, loop n the list, delete the specified element:
>>> name = [' Ten ', ' + ', ' cooki ', ' the ' ', ' ' Alex ', ' the ' ' Kek ', ' Jim ', ' Kek ', ' a ', ' ' 10 ', ' 10 ', ' 10 ', ' 10 ']
>>> for i in range (Name.count (')):
... name.remove (' ten ')
...
>>> Name
[' Cooki ', ' the ' ', ' ' ' ' ', ' ' Alex ', ' the ' Kek ', ' Jim ', ' the ' ' KEK ']
>>>
9. Judging the inclusion relationship of elements and lists
>>> Name
[' Cooki ', ' the ' ', ' ' ' ' ', ' ' Alex ', ' the ' Kek ', ' Jim ', ' the ' ' KEK ']
>>> name = [' Alex ', ' Cooki ', ' Jim ', ' Kek ', ' KEK ']
>>> ' Alex ' in name
True
>>>
10. List to tuple
>>> name = [' Alex ', ' Cooki ', ' Jim ', ' KEK ']
>>> tuple_name = tuple (name)
>>> Tuple_name
(' Alex ', ' Cooki ', ' Jim ', ' KEK ')
>>>
11, the tuple is sent to the list
>>> Tuple_name
(' Alex ', ' Cooki ', ' Jim ', ' KEK ')
>>> list_name = List (tuple_name)
>>> List_name
[' Alex ', ' Cooki ', ' Jim ', ' KEK ']
>>>
12, in Python to determine whether the input is a string or a number
>>> str1 = ' Hello '
>>> str1.isdigit () # #判断是否为数字
False
>>>
>>> Str1.isalpha () # #判断是否为字符
True
>>>
>>> str2 = "123"
>>> str2.isdigit ()
True
>>> Str1.isalpha ()
True
>>>
Use of Python