Getting Started with Python development Basics-day1-python

Source: Internet
Author: User

Programming language classification

Machine language

Direct programming with binary code, direct interaction with hardware, execution speed is very fast, flexible, but the development is difficult, development efficiency is low, lack of portability.

Assembly

The machine language instruction is packaged in English, which is easier to remember than the machine language, directly interacts with the hardware, executes quickly, and executes small files, but the development is relatively difficult and the development efficiency is low.

Advanced language

The syntax is simple, easy to understand, the development difficulty is low efficiency high, after the development test is convenient, but the development procedure needs to undergo the transformation to carry on, therefore the execution efficiency is relatively slow, the portability is high.

Interpretation execution: When the code executes, the interpreter interprets and runs according to the contents of the source code file, and the relative compilation execution speed is slow, but the error is convenient to debug, and the development efficiency is high.

such as Python, PHP, Ruby, JavaScript, etc.

Compile execution: Before the execution of the program, the compiler will compile the source code once to the machine can recognize the instruction file, and then run the compiled file, the speed relative to the table interpretation of the execution is high, but the error after the source code to modify the need to recompile the execution, development efficiency is relatively low

such as C language, C + +, GO, Swift, object-c, etc.

Explain that execution and compilation execution are different in execution efficiency, but the speed of hardware calculation of the current computer, coupled with the constraints of the network environment, execution speed is relatively not the key, development efficiency is the key.

Like Java and C # are mixed languages, that is, both compilation execution and interpretation execution.

About Python

Python Introduction

Python is an interpretive programming language, platform compatibility is high, omit a bunch of fart words, this is a NOTE!!!!

The interpreted language relies on the interpreter, and the Python interpreter executes the code file as follows:

Open the Python interpreter

Python interpreter calls the Py file from the hard disk into memory

The Python interpreter executes the file code that reads into memory, in detail: Py file-bytecode file-interpreter-machine code-execution

The python file does not save the bytecode file during execution, and it is converted to a bytecode file each time the py file is executed.

Python will generate a PYC byte-code file to save when importing the py file.

Python classification

Cpython (most commonly used): Python, the official version of the C language, Cpython converts source code files into PYc bytecode files for use on Python virtual machines

Jpython: Python with Java implementation that dynamically compiles Python code into Java bytecode and then runs on the JVM

Ironpython:python's C # implementation, IronPython compiles Python code into C # bytecode and then runs on the CLR

PyPy (Special): Python-implemented python that compiles Python bytecode bytecode into machine code

Rubypython, Brython .....

In addition to pypy, the execution process is as follows:

The code file first converts the layer bytecode file, the bytecode file into the interpreter, and the interpreter translates into machine code after the output is executed.

Python interpreter version

Version 3, the latest version is 3.6.1

Version 2, the latest version is 2.7.13,2020 year stop update

Getting Started with Python

Installation

Python Linux Version installation

Installation process Turn http://www.cnblogs.com/zero527/p/6920965.html

Python version of Windows installation

Double-click Install, all the way next, remember to tick the auto Add environment variable

The first line of code "Hello World"

The interpreter is used only to test the code, and cannot save the code, want to persist it, need to write the code to the file.

Interpreter execution:

C:\users\mr.chai>Pythonpython3.6.1 (V3.6.1:69C0DB5, Mar, 18:41:36) [MSC v.1900 64bit (AMD64)] on Win32type" Help","Copyright","credits" or "License"  forMore information.>>>"Hello World" #由于解释器自带输出功能, so entering a string automatically gives the output 'Hello World'>>>Print("Hello World"#print为输出, the content of the  output is the content in parentheses Hello world>>>

PY File Execution:

Create a hello.py file with content written to print ("Hello World")

c:\users\mr.chai>python C:\hello.pyhello World

Python file header (Linux)

Executing the hello.py file on Linux is also done with the Python path/hello.py, but the Linux can be executed directly with the./method execution file. hello.py, will be error, because the interpreter is not found, so in the hello.py file to add a header information, identify the location of the interpreter

# #该行只对linux有效, which represents/usr/bin/all Python interpreters, can specify one such as:/usr/bin/python #-*-Coding:utf-8-*-#指定字符编码
Print ('helloWorld')

Content comments

Comment as descriptive text

# single Comment

"' Str ... Str "Triple quotes for multiline comments

module Function Import

Import SYS imports the system module, allowing the file to run extended system functions

Variable

A variable is an abstract concept that is used to denote the state that the program changes when it is run.

Variable composition:

[Variable name]=[variable actual value]

Variable name: variable name General letter or underscore beginning, the rest can be letters and numbers, variable names can not conflict with keywords, such as print, and other system keywords

Variable value: Can change the value, a variable name can be repeated assignment, but the actual value of the variable is the last assignment value, the value of the variable is stored in the memory space

Variable type:

Local variable: A variable that takes effect only in a section of code

Global variables: Variables that are in effect throughout the program's run

Variable assignment and invocation:

# !/usr/bin/env python # -*-coding:utf-8-*-name="Bob" #赋值字符串 age =20 #赋值整数  C10>print(name,age) #输出变量
Print ("My name is%s,i-%s years old."% (Name,age)) # %s represents a placeholder, the first%s invokes the first variable in parentheses, and the second one calls the second variable

A duplicate assignment refers to a reference that changes the variable name and the value of the reference changes.

ID followed by variable, view memory ID number

>>> a=1>>> ID (a)1379185728>>> b=1>>> ID (b)1379185728

Variables occupy a small amount of memory space, no longer open up memory space, will be directly referenced, if the use of large memory space, the reference process will open up new memory space, which is a python optimization mechanism

>>> a="abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ">>> ID (a)2884867588944>>> b="  ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz ">>> ID (b)2884867588624

Input/Output

The input () function in the Raw_input () Python3 in Python2 will turn all user inputs into STR type

>>> name=input ("name:") name:bob>>> age=input (" Age : " ) Age:20>>> Type (name)<class'str'> >>> Type (age)<class'str'>

Getpass module, can hide the input

>>> Password=getpass.getpass ("Pass:")pass:  Print(password)123456



Getpass module, hidden password input
Import Getpass
Name=input ("User name:")
Password=getpass.getpass (' Password: ')

Print ("Username:%s password:%s"% (Name,password)

Getting Started with Python development Basics-day1-python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.