19.6.28

                                                                       Small programming language summary

  Today's learned by studying the history of programming languages; so far, there are three types of language: namely, machine language, assembly language, high

Language. Machine language is direct binary can directly communicate with the computer language, is able to directly operate the hard drive, but it entered a long low expression, and therefore

Machine language say it's obvious shortcoming is the development rate is very low, but it also has its own advantages is that the efficiency is relatively high. Assembly language is a simple English

Labels to represent a binary number, but also be able to directly operate the hard drive, compared with its machine language development more efficient but his efficiency than a machine

Low language. High-level language rather than direct manipulation is hard to explain to people on our dialogue with the computer or compile their own point of view, we now often

The use of high -level languages are divided into two categories, namely, compiled and interpreted. But compiled is the type of one-time translation can complete multiple runs, compiled over

Cheng need to use the compiler, it is a little high efficiency but low development efficiency. Interpreted its work is characterized by line by line translation is read a line translator

Line; Excellent points are the development of high efficiency low efficiency. In comparison, the learning curve is greater than the machine language assembly language is greater than the high-level language, the efficiency of the machine

Language greater than assembly language is greater than the high-level language; and the development efficiency is less than machine language assembly language is less than the high-level language.

 Install python interpreter

    Python currently supports all major operating systems, comes with Python environment on Linux, Unix, Mac system, the system needs to be installed on a Windows look.

    Open official website  https://www.python.org/downloads/windows/  Download Center

Testing the installation 
windows -> Run -> cmd, and then press Enter to bring up the cmd program, enter python, if they can enter the interactive environment, represents the installation was successful.
The coexistence of multiple versions of the demo 
Note: python.exe found in the installation directory, copy, named python2.exe or python3.exe, be sure to keep the original, because the pip tools call it. 

Variables
 What is a variable:
That variable amount of change, the core is the "change" and "quantity" word, change that is a change, that is a measure of the amount of state.

    Why should there be variables:

 
Program execution is change the nature of a series of state change is directly reflected in the implementation of the program, so we need to have a mechanism to reflect changes in or is saved when the program execution state and state. 
For example: 
    the hero is rated 1, Daguai upgrade (change) of 10 
    surviving zombie state True, the plant is killed, then becomes False 
    person's name to egon, it can also be modified to Egon 

    How to define variables:

Variable name (corresponding to the house number, where the value of the spatial points), equal sign, the value of the variable 
name = 'Egon' 
Sex = 'MALE' 
Age = 18 is 
Level = 10

    Variables defined norms:

1. Variable names only letters, numbers, or underscore any combination of 
the first character 2. The variable name can not be a number 
3 keyword can not be declared as a variable name [ 'and', 'as' ,' assert ',' BREAK ',' class', 
'Continue', 'DEF', 'del', 'elif', 'the else', 'the except', 'Exec', 'the finally',
'for', 'from', 'Global' , 'IF', 'Import', 'in', 'IS', 'the lambda', 'not',
'or', 'Pass',' Print ',' The raise ',' return ',' the try ',' while ',' with ',' yield ']

    Defined method:

 
# Hump body
 AgeOfOldboy = 56 is 
NumberOfStudents = 80 
# underscore (recommended) age_of_oldboy = 56 is 
number_of_students = 80

     Defined variable names a bad way

1. variable named Chinese, Pinyin 
2. The variable name is too long 
3. Variable noun lied

    Define the variable will be: id, type, value

 
 
1 equal sign comparison is value, 
2 IS comparison is the id 

# stressed: 
same 1. id, meaning and value must be the same type 
2. value the same type is certainly the same, but id may be different, as follows 
>>> x = 'Info Egon: 18 is' 
>>> = Y 'Egon Info: 18 is' 
>>> ID (X) 
4,376,607,152 
>>> ID (Y) 
4,376,607,408 
>>> 
>>> X == Y 
True 
>>> X Y IS 
False
1 , in interactive mode 
when there is a small Python implementation int integer pool. In order to avoid creating the same value is repeated application efficiency caused by the memory space, Python interpreter created when the starting pool small integer range [ -5,256 ], small integer within the range of the object is global interpreter the range is reused, GC never be recovered 

after creating a - integer between 5-256, a value is taken away directly from the pool directly, e.g.
 >>> = Y. 4 
>>> ID (Y )
 4297641184 
>>> 
>>> X =. 3 
>>> = X +. 1 
>>> ID (X)
 4297641184 

in the PyCharm 
but the python program running PyCharm, PyCharm on performance considerations, will expand the pool of small integers range, such as a string of other immutable types are also included a deal will be the same way, we only need to remember this is an optimization mechanism, as to how much scope in the end, no careful study
Small integer pool

  constant

 
Constant refers to the same amount, such as pai 3.141592653 ..., or the amount will not change in the program is running 
, for example, if the old boy will become the teacher's age, and that this is a variable, but in some cases, he Age will not change, and that is constant. Not in Python on behalf of a special syntax constants, programmers convention with representatives variable name in all caps constant 
AGE_OF_OLDBOY = 56 

# ps-: a dedicated constant defines the syntax of the c language, const int count = 60; once defined as constants, change That will complain 





Guess you like

Origin www.cnblogs.com/sweet-i/p/11104289.html