List of Python data types
A list is a collection of data defended in square brackets "[]", with different members separated by ",". The list can contain any data type, or it can contain other lists, which can be accessed by the list by ordinal. You can sort, add, delete, and so on in a script, and you can change the value of any member in the list.
| List operations |
Describe |
| List.append |
Append member |
| List.count (x) |
Count the number of occurrences of the parameter X in the list |
| List.extend (L) |
Append another list to the list L |
| List.index (x) |
Get the position of the parameter X in the list |
| List.insert () |
Inserting data into the list |
List.pop ()
|
Deletes the last value in the list and returns the deleted value |
List.remove ()
|
Remove a member from a list |
List.reverse ()
|
Reverses the order of the members in the list |
List.sort ()
|
Sort members in a list |
A dictionary is a special kind of data type in Python and is a collection of data that encloses {} with braces. The biggest difference between a dictionary and a list is that the dictionary is unordered, and the members are accessed through keys in the dictionary.
Usually the operation of a dictionary
| Dictionary operations |
Describe |
| Dic.clear () |
Empty dictionary |
| Dic.copy |
Copy Dictionary |
| Dic.get (k) |
Get the value of the key K |
Dic.has_key (k)
|
Whether to include the key K |
| Dic.items () |
Get a list of keys and values |
| Dic.keys () |
Get a list of keys |
| Dic.pop (k) |
Delete key k |
| Dic.update () |
With new members |
| Dic.values () |
Get a list of worthwhile |
Python data type: A file file can also be considered a data type in Python, and a file object is returned when a file is opened with Python's built-in function open
Open (filename,mode,bufsize) fiename the file to be opened mode optional, file Open, R, read-only w overwrite write a append bufsize optional parameter, buffer size E G:user_file=open ("User.log", "R") print (user_file) E:\Python34\python.exe e:/one/day1/day1homework1.py<_io. Textiowrapper name= ' user.log ' mode= ' r ' encoding= ' cp936 ' >process finished with exit code 0
User_file=open ("User.log", "R") User_line=user_file.read () print (user_line) E:\Python34\python.exe e:/one/day1/ Day1homework1.pyduqiu,123wangming,123
User_file=open ("User.log", "R") User_line=user_file.readline () print (user_line) E:\Python34\python.exe e:/one/day1/ Day1homework1.pyduqiu,123process finished with exit code 0
User_file=open ("User.log", "R") User_line=user_file.readlines () print (user_line) E:\Python34\python.exe e:/one/day1 /day1homework1.py[' duqiu,123\n ', ' wangming,123 ']process finished with exit code 0
This article is from the "Ancient Capital Road" blog, please be sure to keep this source http://7157581.blog.51cto.com/7147581/1790683
Python data type (ii)