Python module:
A module is a file that contains all of the functions and variables that you define, followed by a. PY name. Modules can be introduced by other programs to use functions such as functions in the module. Modules are imported in the following ways:
1. Import SYS introduces the sys.py module in the Python standard library, which is the method of introducing a module.
2. SYS.ARGV is a list that contains command-line arguments.
3. Sys.path contains a list of paths that the Python interpreter automatically finds for the required modules.
Syntax for module import:
Import module1[, module2[,... Modulen]
Python bytes Type:
A Bytes object is a sequence of a single byte that is a basic element (8 bits, a value range of 0-255), and is an immutable object.
Python list:
A list is one of the most common data structures in Python.
Create a list by enclosing separate data items separated by commas in square brackets. As shown below:
List1 = [A-C, ' A ', ' B ']
The access list is evaluated by its corresponding subscript, and the subscript count starts at 0:
For example: list1[0] value 1
Update the list, as follows, update the element with subscript 0 to 11:
List1[0] = 11
To delete an element in a list:
Del list1[0]list1.remove (' A ') List1.pop () #删除最后一个元素 and has a return value
Append and insert:
List1.append (' last ') #追加列表最后list1. Insert (1, ' one ') #插入到下标为1的位置
Extension of the list:
List2 = [' x ', ' y ', ' z ']list1.extend (list2)
Copy of list:
List3 = List1.copy () List4 = list1[:]
List statistics, sorting, reversal, and de-subscript:
List1.count (' B ') the number of #统计元素 B list1.sort () #排序list1. Reverse () #反转list1. Index (2) subscript for #取元素 2
Python tuples:
Tuples can be understood as immutable lists, with only two methods: Count and Index
The key to creating a tuple is: ', ' instead of ' () '
Compare the following tup1 and tup2 respectively why type:
Tup1 = (1) tup2 = (1,)
Python Dictionary:
A dictionary is another mutable container model and can store any type of object.
each key value of the dictionary (Key=>value) is split with a colon (:), each pair is separated by a comma (,), and the entire dictionary is enclosed in curly braces ({}) , as shown in the following format:
D = {key1:value1, key2:value2}
The key must be unique, but the value does not have to be.
The value can take any data type, but the key must be immutable, such as a string, a number, or a tuple.
A simple dictionary instance:
Dict = {' Alice ': ' 2341 ', ' Beth ': ' 9102 ', ' Cecil ': ' 3258 '}
You can also create a dictionary like this:
Dict1 = {' abc ': 456};d ict2 = {' abc ': 123, 98.6:37};
Dictionary additions and deletions:
dict["Green"] = "2134" #增del dict["Beth"] #删dict ["Alice"] = "4234" #改
Other Ways to Dictionary:
Dict.keys () dict.values () Dict.items () dict.update (Dict1)
Operation of the string:
Source: http://www.runoob.com/python3/python3-string.html
This article is from the "Boundless" blog, please make sure to keep this source http://tofgetu.blog.51cto.com/12856240/1923843
Basic learning of Python (iii)