python 常用函数笔记
2013-07-31 01:15
357 查看
linux
幂运算:
>>>2**3 或 >>>pow(2,3)
绝对值::
>>>abs(-10)
四舍五入:
>>>round(4.5)
向下取整:
>>>import math
>>>math.floor(32.9)
向上取整:
>>>import math
>>>from math import ceil
>>>math.import(43.3)
转化为整数:
>>>int(32.0)
求平方根:
>>>from math import sqrt
>>>sqrt(9)
求负数的平方根:
>>>import cmath (这里不能用 from math import sqrt) 否则会无法求负数的平方根
>>>cmath.sqrt(-1)
1j
复数的使用:>>>(1+3j)*(9+4j)
打印pi:
>>>from math import pi
>>>pi
将python值转化为字符串:
>>>repr(42) repr是一种函数
>>>str(42) str与int、long一样 是一种类型
>>>`42`
打印一个包含数字的句子:
>>>temp=42
>>>print "The temperature is" + `temp`
input(只能输入数字):
>>>input("Input Enter a number:")
raw_input(输入字符串)
>>>raw_input("Input Enter a string:")
输出长字符串 并且需要换行(用三个单引号或三个单引号,其中输出符号不需要用转义):
>>>print '''This is a long string.
It continues here
And it's not over yet.'''
换行符可直接加在内容中
>>>print 'Hello,\nworld'
输出原始字符串(不用在文中对符号进行转义)
pinrt r'C:\Windows\system32'
list(将字符串列表):
>>>list('hello')
列表删除元素:
>>>names=['Alice','Beth','Cecil','Dee-Dee','Earl']
>>>del names[2]
幂运算:
>>>2**3 或 >>>pow(2,3)
绝对值::
>>>abs(-10)
四舍五入:
>>>round(4.5)
向下取整:
>>>import math
>>>math.floor(32.9)
向上取整:
>>>import math
>>>from math import ceil
>>>math.import(43.3)
转化为整数:
>>>int(32.0)
求平方根:
>>>from math import sqrt
>>>sqrt(9)
求负数的平方根:
>>>import cmath (这里不能用 from math import sqrt) 否则会无法求负数的平方根
>>>cmath.sqrt(-1)
1j
复数的使用:>>>(1+3j)*(9+4j)
打印pi:
>>>from math import pi
>>>pi
将python值转化为字符串:
>>>repr(42) repr是一种函数
>>>str(42) str与int、long一样 是一种类型
>>>`42`
打印一个包含数字的句子:
>>>temp=42
>>>print "The temperature is" + `temp`
input(只能输入数字):
>>>input("Input Enter a number:")
raw_input(输入字符串)
>>>raw_input("Input Enter a string:")
输出长字符串 并且需要换行(用三个单引号或三个单引号,其中输出符号不需要用转义):
>>>print '''This is a long string.
It continues here
And it's not over yet.'''
换行符可直接加在内容中
>>>print 'Hello,\nworld'
输出原始字符串(不用在文中对符号进行转义)
pinrt r'C:\Windows\system32'
list(将字符串列表):
>>>list('hello')
列表删除元素:
>>>names=['Alice','Beth','Cecil','Dee-Dee','Earl']
>>>del names[2]
相关文章推荐
- python 一些常用函数笔记
- python学习笔记(三):常用函数和运算优先级
- Python入门笔记(Python常用函数<部分>及小知识点)
- 【Python3 笔记】常用函数 & 语法
- Python学习笔记之常用函数及说明
- Python学习笔记 —— 字符串及常用函数
- Python学习笔记——一些常用函数、常见错误总结
- python学习笔记——常用类库和函数——日期时间
- Python数据分析常用函数笔记
- [学习笔记]Python 常用函数
- python-基础笔记6-文件处理常用函数
- Python学习笔记之—— File(文件) 对象常用函数
- python入门笔记---常用函数举例和总结
- Python学习笔记(4)——常用函数
- Python笔记:random模块常用函数
- Python学习笔记(二):条件控制语句与循环语句及常用函数的用法
- python 学习笔记(3) 各种数据类型常用的函数
- Python常用函数笔记
- python 笔记(刷题常用函数)
- python学习笔记17-常用函数总结整理