Introduction of an Interpretive language--python

Source: Internet
Author: User
Python is an interpreted language

Python 2 or 3 choice:

Python 2.7 is the latest version of 2 and the last version, update support will stop the update until 2020, but the company is now in use or has been developed to continue to use Python2, so the update of this transition period is still a part of the way to go,

Python 3 will be a better choice for the long term (this is for beginners only) and of course learn python3 while learning about the different features of 2 and 3.

Installation and Configuration

Windows

1、下载安装包

https: / / www.python.org / downloads / 2 、安装 默认安装路径:C:\pythonXX 3 、配置环境变量 【右键计算机】 - - 》【属性】 - - 》【高级系统设置】 - - 》【高级】 - - 》【环境变量】 - - 》【在第二个内容框中找到 变量名为Path 的一行,双击】 - - > 【Python安装目录追加到变值值中,用 ; 分割】 如:原来的值;C:\pythonXX,切记前面有分号

Linux, Mac

无需安装,原装Python环境

ps:如果自带 2.6 ,请更新至 2.7或其他版本 First Program
1 print ' Hello world! '  #python2的写法2 print (' Hello world! ') #python3的写法

declaring Variables
Name= ' Tom '

Rules for variable definitions:

      • Variable names can only be any combination of letters, numbers, or underscores

      • The first character of a variable name cannot be a number

      • The following keywords cannot be declared as variable names
        [' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' exec ', ' finally ', ' for ', ' F ' Rom ', ' Global ', ' if ', ' import ', ' in ', ' was ', ' lambda ', ' not ', ' or ', ' pass ', ' print ', ' raise ', ' return ', ' try ', ' while ', ' WI Th ', ' yield ']

assigning values to variables
Name=      =name    (name2)

Character encoding

Tell the Python interpreter what code to use to execute the source code at the beginning of the file, i.e.:

#!/usr/bin/env python#-*-coding:utf-8-*-  #告诉python字符编码  print "Hello, World"

Comments

When the line stares: # is annotated content

Multiline Comment: "" "Annotated Content" ""

Initial knowledge of data types

1. Digital

2 is an example of an integer.
Long integers are just larger integers.
3.23 and 52.3E-4 are examples of floating-point numbers. The e tag represents a power of 10. Here, 52.3E-4 means 52.3 * 10-4.
( -5+4j) and (2.3-4.6j) are examples of complex numbers, where -5,4 is a real number, j is an imaginary number, and what is the plural in mathematics?

int (integral type)

On a 32-bit machine, the number of integers is 32 bits and the value range is -2**31~2**31-1, which is -2147483648~2147483647
On a 64-bit system, the number of integers is 64 bits and the value range is -2**63~2**63-1, which is -9223372036854775808~9223372036854775807long (Long integer)
Unlike the C language, Python's long integers do not refer to the positioning width, that is, Python does not limit the size of long integer values, but in fact, because of limited machine memory, we use a long integer value can not be infinite.
Note that, since Python2.2, Python automatically converts integer data to long integers if an integer overflows, so it does not cause any serious consequences if you do not add the letter L after long integer data.
Float (float type) Literacy First
A floating-point number is used to process real numbers, which are numbers with decimals. Similar to the double type in C, accounting for 8 bytes (64 bits), where 52 bits represent the bottom, 11 bits represent the exponent, and the remaining one represents the symbol.
Complex (plural)
The complex number consists of real and imaginary parts, the general form is X+yj, where x is the real part of the complex, and Y is the imaginary part of the complex, where x and y are real numbers. Note: Small number pools exist in Python:-5 ~ 257 2, Boolean true or False 1 or 03, string
"Hello World"

Receive user input

#!/usr/bin/env python#_*_coding:utf-8_*_  #name = raw_input ("Please enter user name") #只有 Python 2.x has this notation name=input (' Please enter username: ') Print (' Hello ' +name)

If Else ...

#!/usr/bin/env python#-*-coding:encoding-*-age=int (Input (' Please enter Age: '))        #接收一个age值, this is because it is an int type, so you need to cast the IF AGE<100:       print (' You're small ')    #判断age的值小于100的时候输出 "You're Still Young" else:print (' You're old ')   #否则输出 "You're old."

If elif else ...

#!/usr/bin/env python#-*-coding:encoding-*-my_age=22           #定义一个自己的年龄age =int (Input (' Please enter age ')  #接收一个年龄if age==my _age:print (' guessed right ')   #如果输入的值等于my_age的值 output guessed the elif age<my_ageprint (' Guess small ')    #输入的值小于my_age的值, the output was small else:print ( ' Guess the big ')     #负责显示猜大了

While loop ...

#!/usr/bin/env python#-*-coding:encoding-*-count=0         #定义一个值为count的计数器while True:       print (count)  # If it's true, it's a loop. This is a dead loop and does not stop the program will always execute count+=1    #循环一次给计数器 +1

For loop ...

#!/usr/bin/env python#-*-coding:encoding-*-for i in range print (i)                #最简单的循环打印10次

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.