1.运算符
+(加),-(减),*(乘),/(除),%(取余),**(平方)
2.获取输入
input() #函数获取用户的输入,将字符串和数字转换成整数
raw_input() #函数获取用户的输入,结果被看作原始字符串
test = input("Pleae enter your name: ") #intpu "jackm" or 3,此函数读取参数加入"",数字不用加
print test # result is 'jackm' or '3'
test = raw_input("Please enter you name: ")# jackm or 3
print test #resust is jackm or 3
3.导入模块
语法:import module_name
import math
math.floor(32.9);#浮点数计算
可以使用int()函数将浮点数转换成整数
int(math.floor(32.9));
语法:from 模块 import 函数(方法)
from math import sqrt
sqrt(9) #result 3.0
int(sqrt(9)) #resutl is 3
4.cmath和复数
import cmath
cmath.sqrt(-1) # result 1j 复数
5.拼接字符符(+) #在PERL里的(.)和该符号具有同样的功能
x = 'Hello '
y = 'Jackm'
x + y # result is 'Hello Jackm'
6.字符串表示:str() and repr()
str函数,它会把值转换成合理的形式的字符串,可以更好的理解
print str(10000L) # result is 10000 #将值转换成字符串
reprt()函数,它是会把字符串转换为合法的python表达式
print repr(10000L) #result is 100000L #返回值的字符串表示形式
7.其他函数
round(number,[ ndigits]) #根据精度对数字四舍五入
long(ojbect) #将字符串和数字转换为长整数
pow(x,y[,z]) #返回x的y次幂(所得结果对z取模)
help() #提供交帮助
abs(number) #返回数字的绝对值
python入门-基础知识
最新推荐文章于 2024-09-09 23:28:21 发布