The founder of Python is called Guido van Rossum (Guido van Rossum)
Python is an interpreted language
Interpreted language
Pros : Good compatibility (with interpreter installed), modify code to run directly on it, deploy fast, flexible
Cons : Each run needs to be explained, performance is not as good as the compiled language
Compiled languages
Advantages : Do a compile before running, run directly after compiling, program execution efficiency is high
cons : The modification will require the entire recompile, poor platform compatibility, need to be compiled according to different operating systems
1. The PYc bytecode file is generated only when import is imported into the Py file, which can be executed directly in place of the source file.
2. But each time the py file is executed, the resulting bytecode is not preserved, that is, each time the py file is executed, it is to be re-experienced again: Py file--byte code-->python interpreter--machine code, each time is a re-interpretation of the execution of the process.
Python is a language in which the code written in this language needs to be interpreted by a Python interpreter, and the interpreter is categorized as follows:
- Cpython (most commonly used version)
The official version of Python, implemented using the C language, is the most widely used, and the CPython implementation converts the source file (py file) into a bytecode file (PYc file) and then runs on the Python virtual machine.
- Jyhton
Python Java implementation, Jython will dynamically compile Python code into Java bytecode, and then run on the JVM.
- IronPython
In Python's C # implementation, IronPython compiles Python code into C # bytecode and then runs on the CLR. (similar to Jython)
- PyPy (Special)
Python implements Python, which compiles Python bytecode bytecode into machine code.
- Rubypython, Brython ...
PyPy, the Python bytecode is further processed on the basis of Python, which improves execution speed!
You need to give hello.py execute permission before execution in Linux, chmod 755 hello.py
Python header file
#!/usr/bin/env python
# -*- coding: utf-8 -*-Notessingle line: #Multiple lines: "" "" "" "" " Execute script incoming parameters
Python has a large number of modules, which makes developing Python programs very concise. The class library includes three:
- Python-supplied modules
- Industry-Open Source modules
- Modules developed by programmers themselves
Python internally provides a SYS module where SYS.ARGV is used to capture parameters passed in when executing a python script
| 123456 |
#!/usr/bin/env python# -*- coding: utf-8 -*- import sys printsys.argv |
Perform
c:\users\administrator>python D:\python_test\hello.py arg1 arg2 arg3['d:\\python_test\\hello.py 'arg1 ' arg2 'arg3']
PYc FileWhen you execute Python code, if you import a different. py file, a. pyc file with the same name is automatically generated during execution, which is the bytecode generated after the Python interpreter was compiled. Bytecode can also be obtained by anti-compilation code
Variable declarations and references
Identifier naming
1. Variable names can only be letters, numbers, underscores
2. Cannot start with a number
3. Do not use keywords as variable names
Assigning values to variables
can use ID (view)
Input/Output
Python2
raw_input () directly reads the input from the console (any type of input it can receive). For input () , it wants to be able to read a valid Python expression, that is, you must enclose it in quotation marks when you enter a string, or it will throw a syntaxerror,raw_input () to treat all the input as a string. Returns the string type. Input (), which has its own characteristics when treated with a pure digital input, returns the type of the number entered (int, float)
Input in Python3 is equivalent to Raw_input in Python2
condition, fraction, cycle practice
1. Output 1 2 3 4 5 6 8 9 10
i=0 while i<10: i+=1 if i==7: Continue Else: print (i)
View Code
2.1-100 Odd in output
i=0 for in range (1,101): if i%2==0: continue Else: print(i)
View Code
3. Output 1-100 Even
i=0 for in range (1,101): if i%2!=0: continue Else: print(i)
View Code
4. Calculate 1-2+3-4+5.....99
j=0 for in range (1,100): if i%2!=0: J=j+i Else: J=j-iprint(j)
View Code
5. Calculate 1+2+3+4..+100
num=0 for in range (1,101): num=i+num Print (num)
View Code
6. Analog login operation, 3 times chance
ImportGetpasscount=3 whileCount>0:name=input ("Please enter user name:") passwd=getpass.getpass ('Please enter your password:') ifname=="Shuai" andpasswd=="Zhenshuai": Print("Here comes the handsome man! ") Break Else: Count-=1ifCount>0:Print("you can still", Count,"times! ") Else: Print("Get outta here! ")View Code
Python Programming (i)