简
- python
- 输入输出函数
- input() :用户用于读取键盘输入的函数,返回值为“string”类型
- 运算函数
- abs(x) :x的绝对值
- int(x) :将x转换成整型(截掉小数部分)
- float(x):浮点数
- divmod(x,y):返回(x//y,x%y)
- complex(re,im):返回一个复数,re是实部,im是虚部
- pow(x,y):计算x的y次方
- bool(x):输出True或False
- range(stop):依次生成一个(0~stop)的数
python
>>> import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
>>>
输入输出函数
input() :用户用于读取键盘输入的函数,返回值为“string”类型
不管输入什么类型的字符,返回都是字符型的
>>> a=input("请输入:")
请输入:123
>>> print(type(a))
<class 'str'>
>>> type(a)
<class 'str'>
>>> b=input()
ads
>>> print(b)
ads
>>> print(type(b))
<class 'str'>
>>> c=input()
12.3
>>> print(type(c))
<class 'str'>
>>> print(c)
12.3
一次可以有多个输入,调用split()函数,调整输入的间隙控制符
a,b,c =input(":").split(',')#用‘,’隔开
d,e,f =input(':').split(' ')#用‘ ’隔开
print(a,b,c)
print(d,e,f)
输出结果:
运算函数
abs(x) :x的绝对值
int(x) :将x转换成整型(截掉小数部分)
float(x):浮点数
divmod(x,y):返回(x//y,x%y)
x//y:向下取整
complex(re,im):返回一个复数,re是实部,im是虚部
pow(x,y):计算x的y次方
x**y:计算x的y次方
如果加入第三个参数,则结果对第三个参数取余
即:222%5=3
bool(x):输出True或False
range(stop):依次生成一个(0~stop)的数
range(stop) — 依次生成一个(0~stop)的数
例如:
range(5)
打印输出:
0
1
2
3
4
range(start,stop) — 依次生成一个(start~stop)的数
例如:
range(5,10)
打印输出:
5
6
7
8
9
range(start,stop,step) — 依次生成一个(start~stop)的数,跨度为step
例如:
range(3,10,2)
打印输出:
3
5
7
9