Iv. installation of Python
Windows
1
、下载安装包
https:
/
/
www.python.org
/
downloads
/
2
、安装
默认安装路径:C:\python27
3
、配置环境变量
【右键计算机】
-
-
》【属性】
-
-
》【高级系统设置】
-
-
》【高级】
-
-
》【环境变量】
-
-
》【在第二个内容框中找到 变量名为Path 的一行,双击】
-
-
> 【Python安装目录追加到变值值中,用 ; 分割】
如:原来的值;C:\python27,切记前面有分号
linux、Mac
无需安装,原装Python环境
ps:如果自带
2.6
,请更新至
2.7
V. Hello World Program
Create a file under Linux called hello.py, and enter
Print ("Hello world!")
Then execute the command: Python hello.py, output
localhost:~ jieli$ vim hello.py localhost:~ jieli$ python hello.py Hello world!
Specify interpreter
When executing Python hello.py in the previous step, it is clear that the hello.py script is executed by the Python interpreter.
If you want to execute a python script like executing a shell script, for example, you ./hello.py would need to specify the interpreter at the head of the hello.py file, as follows:
#!/usr/bin/env python print "Hello,world"
So, execute:. /hello.py Can.
PS: Need to give hello.py execute permission before execution, chmod 755 hello.py
Executing in the interactive device
In addition to writing the program in the file, you can also call the Python's own interactive running code,
localhost:~ jieli$ python python 2.7.10 (default, OCT, 18:05:06) [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700 .0.59.5)] on Darwintype ' help ', ' copyright ', ' credits ' or ' license ' for more information.>>> print ("Hello world!" ) Hello world!
Six, variable \ character encoding
declaring variables
#_ *_coding:utf-8_*_ name = "Alex Li"
The code above declares a variable named: Name, and the value of the variable name is: "Alex Li"
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 = "Alex Li" name2 = name print (name,name2) name = "Jack" Print ("What's the value of name2 now?")
Comments
When the line stares: # is annotated content
Multiline Comment: "" "Annotated Content" ""
This article is from the "Sandshell" blog, make sure to keep this source http://sandshell.blog.51cto.com/9055959/1974951
Python path, Day1-python base 1