First, install the PYTHON34
Windows
-
On the Python website (https://www.python.org/downloads/) Download the installation package and install it.
-
The default installation path for Python is: C:\Python34
-
To configure environment variables:【右键计算机】--》【属性】--》【高级系统设置】--》【高级】--》【环境变量】--》【在第二个内容框中找到 变量名为Path 的一行,双击】 --> 【Python安装目录追加到变值值中,用 ; 分割】
Two, the first Python program
1. Execute in the interactive: directly invoke Python's own interactive run code (for temporary debugging)
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/8A/74/wKioL1gxUGGQyprxAAAW1DirqrQ026.png "title=" 1.png " alt= "Wkiol1gxuggqyprxaaaw1dirqrq026.png"/>
2. write the program in the file to execute
(1) Installing Pycharm (http://www.jetbrains.com/pycharm/download/)
(2) Create a new project and Python File
(3) Write code
Print ("Hello world!")
(4) Operation
Iii. Defining variables
Variables are stored and called in the program. Variables are equivalent to a container that stores data in memory. (The difference between memory and hard disk: memory is faster than hard disk, memory is temporary storage, hard disk is permanent storage)
#!/user/bin/env python#-*-coding:utf-8-*-user_name = "Grace" #申明一个字符串变量age = #申明一个数字变量
Rules for variable definitions:
1. Single quotes, double quotes, and triple quotes are all strings
2. Variables should be meaningful and make people more clear
3. Variable names can only be any combination of letters, numbers, and underscores
4. The first character of a variable name cannot be a number
5. Cannot declare variable name with keyword
Four, character encoding
Bytes: 8 bits constitute 1 "bytes", which is the basic unit of measurement for storage space. 1 bytes can store 1 English letters or half Chinese characters, in other words, 1 Chinese characters occupy 2 bytes of storage space.
1kb=1024b 1MB=1024KB  1GB=1024MB  1TB=1024GB
1. ASCII (American Standard Code for information interchange, US Standards Information Interchange Code) is a Latin alphabet based computer coding system, mainly used to display modern English and other Western European languages,
It can only be represented by a maximum of 8 bits (one byte), that is: 2**8 = 256-1, so the ASCII code can only represent a maximum of 255 symbols.
2. It is clear that the ASCII code cannot represent all the words and symbols in the world, so it is necessary to create a new encoding that can represent all the characters and symbols, namely: Unicode
Unicode (Uniform Code, universal Code, single code) is a character encoding used on a computer. Unicode is created to address the limitations of the traditional character encoding scheme, which sets the unity of each character in each language and
and a unique binary encoding, which specifies that characters and symbols are represented by at least 16 bits (2 bytes), i.e. 2 **16 = 65536,
Note: Here is a minimum of 2 bytes, possibly more
3. UTF-8, is the compression and optimization of Unicode encoding, he no longer uses a minimum of 2 bytes, but all the characters and symbols are categorized: the contents of the ASCII code is saved in 1 bytes, the characters in Europe are saved in 2 bytes,
East Asian characters are saved with 3 bytes ...
Python2 a few versions of the default Ascill, you can specify a character set:
#!/usr/bin/env python#-*-coding:utf-8-*-print "Hello, World"
V. Notes
Single-line gaze: # Annotated content
Multi-line Comment: ' commented content ' (' ' represents a multiline string, multiline string is placed directly in Python and will be ignored by Python)
Six, formatted string
1. Input is a string that is received by default in Python3
2.%s can be passed into a string or integer class,%d can only pass in integer class,%f floating-point number type
3. Three single quotation marks ("") can be used for multiple lines of string, define variables as multiple lines of string, output multi-line string
Name = input ("Input your Name:") age = Int (input ("Input your:")) #convert str to intjob = input ("Input your Job:") Messa Ge= ' Information of user%s:_______________________name:%sage:%fjob:%s---------End-----------'% (Name,name,age, Job) print (message)
Vii. Expressions If ... else
Use a login verification to illustrate:
Rightname = "tt" password = "WPL" userName = input ("Please enter your name:") UserPassword = input ("Please enter your Passwor D: ") #Python is a forced indent language that controls dependencies by indenting if userName = = Rightname and UserPassword = = Password:print (" Welcome login ... ") Else: Print ("Your user name or user password is invalid")
Viii. expression for loop
To explain by guessing the age:
age = count = i (): (, Count) count < : guess_age = ( () ) guess_age == age: () guess_age > age: () : () count += : user_answer = () user_answer = = : count = : ()
The code has a maximum of 10 loops, with two loops asking the user to continue guessing, and not having the user guess the age at the time when the user responds with Y. Instead, start guessing age after entering the next cycle.
This article is from the "12131753" blog, please be sure to keep this source http://12141753.blog.51cto.com/12131753/1874780
Python Learning path-Python basics-One