day 1 and job notes

 Reference: https: //www.cnblogs.com/alex3714/articles/5465198.html

A, Python and other programming languages ​​description:

1, origin

Python founder of Guido van Rossum (Guido van Rossum). During Christmas 1989, Guido van Rossum in Amsterdam in order to pass the time, determined to develop a new script interpreter, ABC language as an inheritance.  

2, Type

Python is an interpreted, dynamic, strongly typed language, belong to the more secure language.

Compiled vs interpreted

Compiled
advantages: The compiler usually have pre-compiled code optimization process. Because the compiler only once, do not need to compile and run time , so the program execution of compiled languages high efficiency . It can operate independently from the locale.
Cons: After compiling If you need to modify the entire module needs to be recompiled. Compile time to generate machine code according to the corresponding execution environment, migration there will be problems between different operating systems, according to the environment you need to compile and run a different operating system executable files.

Interpreted
advantages: a good platform compatibility, can run in any environment, provided that the interpreter (Virtual Machine) installed. Flexible and modify the code when direct modification can be quickly deployed without downtime maintenance.

Disadvantages: time for each run should explain it again, not as a compiled language performance .

 

Dynamic and static languages

(1) dynamically typed languages : dynamically typed language is the only language data type checking is done during operation, that is, when a dynamically typed programming language, will never need to specify the data type of any variable, the language will when you first assigned to variables, data types internally recorded. Python and Ruby is a typical dynamically typed languages, various other scripting languages such as VBScript also how many of dynamically typed languages.

(2) statically typed languages : statically typed language with dynamically typed languages just the opposite, its data type is checked at compile the meantime, that the written procedures to declare the data types of all variables , C / C ++ is a statically typed language a typical representative of the other statically typed languages as well as C #, JAVA and so on.

 

Strongly typed and weakly typed language definition language

( 1) strongly typed language : Once a variable is assigned a data type, if not through coercion, then it will always be this type of data. For example: if you define an integer variable a, then the program will be impossible as a string type process. Strongly typed language is type-safe language.

(2) weakly typed definition language : the value of a variable can be assigned different data types. Weakly typed language is defined unsafe type of language.

 

Strongly typed language in speed may be slightly inferior to the weak type definition language, but strongly typed language brings rigor can effectively avoid many mistakes. In addition, "the language is not a dynamic language" between "the language whether the type of security" is absolutely no connection!
For example: Python language is dynamic, is strongly typed languages (type-safe languages); VBScript language is dynamic, is weakly typed definition language (language unsafe type); the JAVA language is static, is strongly typed languages (type-safe language).

 

3, thus giving the advantages and disadvantages of Python:

Look at the advantages

  1. Python position is "elegant" and "clear", "simple", so Python program always looks easy to understand for beginners to learn Python, not only easy entry, and deep down in the future, you can write those very, very complex programs.
  2. Development efficiency is very high, Python has a very powerful third-party libraries, you basically want to achieve through any computer functions, Python official library has a corresponding module support, directly after downloading calls, and then to build on the foundation of the library and greatly reduce the development cycle, to avoid duplication of-create the wheel.
  3. High-level language ---- When you write programs in Python, you do not need low-level details such as managing the memory of a class of your program uses
  4. Portability ---- Due to its open-source nature, Python has been ported on many platforms (changed to make it work on different platforms). If you are careful to avoid the use depend on the characteristics of the system, then all your Python programs without modification to run on almost all platforms on the market
  5. Scalability ---- If you need a critical piece of code to run very fast or want some algorithms are not open, you can put part of your program in C or C ++, and then use them in your Python programs.
  6. Embeddable ---- you can embed Python within your C / C ++ program, which provides scripting capability to your program's users.

Look shortcomings

  1. Slow, Python's speed compared to the C language does a lot slower, but also slower compared with JAVA, so this is a lot of so-called Daniel disdains the main reason for the use of Python, but in fact referred to here running slow in in most cases the user is unable to perceive directly, you must use test tools can be reflected. (This drawback can be used Pypy interpreter remission)
  2. Code can not be encrypted, because Python is an interpreted language, its source code is stored in clear text, but I do not think it can be considered a drawback, if your project requires that the source code must be encrypted, then you should not start come and go with the Python implementation.
  3. Thread can not take advantage of multi-CPU problem, which is a disadvantage Python is the most criticized people, GIL namely the global interpreter lock (Global Interpreter Lock), is a computer programming language interpreter for synchronizing thread tools so that any time there is only one thread execution, Python threads are native operating system threads. On Linux is pthread, on Windows Win thread, executed entirely by the operating system thread scheduling. There are a main thread of execution threads, and a plurality of user programs within a python interpreter process. Even on multi-core CPU platform, because of the GIL, the prohibition of parallel execution of multiple threads. About a compromise solution to this problem, and we have discussed in detail in later chapters threads and processes.

4, Python interpreter related

CPython (official)

IPython 

Pypy (worth a try)

 Second, variable

Variables like a temporary storage area, without knowing its true power lies in their stored value will be able to operate them

Variables defined rules:

    • Variable names can be any combination of letters, numbers or underscore
    • The first character variable names can not be digital
    • The following keywords can not be declared variable name
      [ 'and', 'as' ,' assert ',' break ',' class', 'continue', 'def', 'del', 'elif', 'else', ' except ',' exec ',' finally ',' for ',' from ',' global ',' if ',' import ',' in ',' is', 'lambda', 'not', 'or' , 'pass', 'print' , 'raise', 'return', 'try', 'while', 'with', 'yield']

>>> name = 'alex'
>>> name2 = name
>>> print('my name is',name,name2)
my name is alex alex
>>> name = 'randomdoor'
>>> print(name,name2)
randomdoor alex

>>> PI = 3.14 # take given constant (variable names capitalized)

 

 Third, the character encoding

For Chinese:
ASCII ->
GB2312 (1980) ->
GBK (1995) ->
GB18030 (2000)
# these encoding methods are backward compatible with the existence of a Chinese character requires three bytes
for English :
ASCII ->
Unicode ->
UTF-8 # enlish: 1byte Zhongwen: 3 bytes

 

Fourth, the user interaction program

msg= '''name = 'alex'
name2 = 'randomdoor'
print("my name is ", name2)'''
print(msg)
>>>
= name 'Alex' 
NAME2 = 'randomdoor' 
Print ( "My name IS", NAME2) 
# '' 'may be used for multi-line comment and reference

 

 1 name = input("name:")
 2 age = int(input("age:"))         #int:string-->interger
 3 print(type(age), type(str(age))) #str:interger-->string
 4 job = input("job:")
 5 salary = input("salary:")
 6 
 7 info = '''
 8 -------- info of  %s  -----  
 9 Name:%s 
10 Age:%d
11 Job:%s
12 The Salary:% S
 13 is  ' '' % (name, name, Age, Job, the salary)
 14  # % S string 
15  # % D digital 
16  # % F float 
. 17  
18 is >>> 
 . 19 ------- - info of randomdoor -----
 20 is  the Name: randomdoor 
 21 is Age: 20 is
 22 is  the Job: Student 
 23 is the Salary: 0
Assignment method
Assignment Method Two
 1 name = input("name:")
 2 age = int(input("age:"))         #int:string-->interger
 3 print(type(age), type(str(age))) #str:interger-->string
 4 job = input("job:")
 5 salary = input("salary:")
 6 
 7 info3 ='''
 8 -------- info of {0} -----
 9 Name:{0}
10 Age:{1}
11 Job:{2}
12 Salary:{3}
13 '''.format(name,age,job,salary)
14 print(info3)
Assignment Method Three

 

 

flow chart

 version1:

user_name = 'gbw'
pass_word = 'abc123' #可以将数据存在字典里
while True:
    username = input('username:')
    if username != user_name:
        print("username does not exist, try again")
    else:
        for i in range(3):
            psword = input('password:')
            if psword == pass_word:
                print('Welcome!')
                break
            else:
                print('password is wrong, try again')
        else:
            break

 

Guess you like

Origin www.cnblogs.com/randomdoor-2019/p/11183139.html