python的集成开发环境
IDLE 标准python 开发环境。
Pythonwin 面向Windows的开发环境。
交互式解释器
当输入python的时候,会出现‘>>>’ 的提示,尝试输入
print 'Hello, world!'
当出现语法错误会有如下显示
_ sytaxerror : invalid syntax _
并且注意哪里有语法错误,都会有python的贴心提示:‘^’,‘→’,注意观察改正就行了。
基本的运算功能
2+2
>>> 4
>1/2.0 #change the format automatically
>>>0.5
>1/2
>0
包括下列的一些基本运算与c语言差不多
整除→// 乘方→** 取余→% 乘方的函数→pow(2.3)=2**3
如何获取用户输入input VS raw_input
$input ('my name is ')
>>> my name is #just input you name ,such as "tom"
例子中形象说明了区别,使用input需要+引号,单引号双引号都行,使用raw_input 不需要加引号,原因就是raw_input 函数将所有输入都当成了原始数据。
如何利用模块功能
import math
math.floor(32.9)#floor-向下取整 ceil-向上取整 round-四舍五入
>> 32.0
>from math import sqrt#这种形式可以直接使用函数,不需要加点了。
>sqrt(9)
>>>3.0
>import cmath #可以用来计算复数
how to run the python script
use ‘cd ’ to transfer your directory and use the command
python hello.py #注意有些程序不认sudo,有些需要管理员权限。
如何让脚本像普通程序运行呢
不管python程序在哪里都能够运行,note:
#! /usr/bin/env python #把这句话加到python程序的第一行,有些系统的python路径可以因系统而异,注意更改就好。
¥ chmod a+x hello.py #让脚本文件有可执行的属性