python 学习笔记之基础知识总结

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 #让脚本文件有可执行的属性
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值