1. What is an identity (zhi) character?
In Python, when we are programming, the name is called identifier. Where variables and constants are one of the identifiers
2. Naming rules for identifiers
The first character of a ① identifier must be a letter or an underscore, not a number or a special symbol, etc.
② In addition to the first character, the other can make the letter underlined and the number
③ case Sensitive Stuname and stuname are not the same identifiers
3. Common Python Keywords
A keyword in python refers to an identifier that comes with a special meaning in the system
Commonly used Python keywords are: and elif Global or else Pass break continue import class return for while etc.
4. What is a Python object
The types of objects built into Python (numbers, strings, lists, Ganso, dictionaries, collections, and so on), in fact, in Python, everything is an object
5, detailed pickle pickling
In Python, if we have some objects that require persistent storage and do not lose the type and data of our objects, we need to serialize them and store them in memory or in a file. After serialization, we revert back to the original data when we need to use it.
This process of serialization, we call it pickle, which is pickled.
A series of process codes:
#Encoding:utf-8#The pickle module is self-contained in Python, and we only need to import this module toImportPickle#dumps (objects) serializes an objectscorelist=[98,97,65,12,36]listwithdump=pickle.dumps (scorelist)PrintListwithdump#loads (string) restores the object, and the object type reverts to its original formatnewscorelist=pickle.loads (listwithdump)Printnewscorelist#dump (object file), storing objects in a file serializationStudents= ("Zhang San","John Doe","Harry","Zhao Liu") File1=file ("BACK.PKL","WB") Pickle.dump (students,file1,true) file1.close ()#load (object,file) will dump () the data stored in the file replyFile2=file ("BACK.PKL","RB") restudents=pickle.load (file2)Printrestudentsfile2.close ()
Separate:
① serialization of an object
# dumps (objects) serializes an object scorelist=[98,97,65,12,36]listwithdump=pickle.dumps (scorelist) Print Listwithdump
The result of the output is
② to restore the serialized object to its original format
# loads (string) restores the object, and the object type reverts to its original format newscorelist=print newscorelist
The output result is
has been restored to its original
③ storing objects inside a file serialization
Students= (" Zhang San "," John Doe "," Harry " , " Zhao Liu ") file1=file ("back.pkl"," WB " ) Pickle.dump (students,file1,true) file1.close ()
After execution, the file directory list has one more file:
Open the file with the following contents:
④ dump () data stored in the file reply
File2=file ("back.pkl","RB") restudents= Pickle.load (file2)print restudentsfile2.close ()
The output is:
The encoding corresponds to the Chinese character one by one and is also a successful restoration.
Python-08:python Syntax Basics-Identifiers and objects