Python语言笔记一 入门py
小标 2018-12-10 来源 : 阅读 1246 评论 0

摘要:本文主要向大家介绍了Python语言笔记一 入门py,通过具体的内容向大家展示,希望对大家学习Python语言有所帮助。

本文主要向大家介绍了Python语言笔记一 入门py,通过具体的内容向大家展示,希望对大家学习Python语言有所帮助。

id()函数,是python内置函数,查看每一个对象的地址。
>>> help(id);
Help on built-in function id in module builtins:

id(...)
    id(object) -> integer

    Return the identity of an object.  This is guaranteed to be unique among
    simultaneously existing objects.  (Hint: it's the object's memory address.)

>>> id(3);
505986504
>>> id(3);
505986504
>>> id(3.0);
20256768
type();函数查看对象的类型。
>>> type(3);

>>> type(3.0);

>>> type('str');

>>> type([1,2,3]);

>>> type((1,2,3));

python中对象有类型,变量无类型,和js很想,这让我们c系类的语言者有些难受。
>>> x=66;
>>> x
66
>>> x="dflx";
>>> x
'dflx'
python支持大整数运算,学过计算机组成原理的 都知道,计算机进行浮点数运算的时候会出现溢出现象。
>>> 2**64;
18446744073709551616
>>> 2**173;
11972621413014756705924586149611790497021399392059392
python只是解决了大整数运算,但是浮点数和整数不同,它存在上下限,超过会溢出。
>>> 1000.0**8000
Traceback (most recent call last):
  File "", line 1, in 
    1000.0**8000
OverflowError: (34, 'Result too large')
除法运算,在python3中,要取整,需要 \\
>>> 2/5;
0.4
>>> 2//5;
0
>>> 5//2;
2
异常的计算,不必纠结。
>>> 10.0/3
3.3333333333333335
>>> 0.1+0.2
0.30000000000000004
出现这种问题,主要在十进制和二进制的转换,比如0.1想要转换成二进制,会是一个循环的二进制表示不出来。

解决上面的问题,可以采用轮子,python中的模板来解决。
>>> import decimal;
>>> a=decimal.Decimal("10.0");
>>> b=decimal.Decimal("3");
>>> a/b;
Decimal('3.333333333333333333333333333')
四舍五入
>>> round(3.1415926,3);
3.142
>>> help(round);
Help on built-in function round in module builtins:

round(...)
    round(number[, ndigits]) -> number

    Round a number to a given precision in decimal digits (default 0 digits).
    This returns an int when called with one argument, otherwise the
    same type as the number. ndigits may be negative.
math库,是我最喜欢的函数库,可以进行数学运算,如果在小屁孩面前展示其功能一定会惊讶它们,作为一个数学老师,会几何画板,已经可以让学生们认为你很厉害了,如果会mathematica,甚至python会让它们更加崇拜;。
>> import math;
>>> dir(math);
['__doc__', '__loader__', '__name__', '__package__', 
'__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 
'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 
'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 
'fsum', 'gamma', 'hypot', 'isfinite',
 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 
'modf', 'pi', 'pow', 'radians', 'sin', 'sinh',
 'sqrt', 'tan', 'tanh', 'trunc']
展示一下其功能
>>> math.pi;
3.141592653589793
>>> math.e;
2.718281828459045
>>> pow(2,3);
8
>>> math.sqrt(4);
2.0
编写了一个helloworld.py的python文件
#!/user/bin/env python
#coding:utf-8
str_a="hello world";
print(str_a)
在dos中运行。
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.
C:\Documents and Settings\Administrator>cd c:\python34
C:\Python34>python helloworld.py
hello world

行了,今天就水到这里,别问我,为什么用dos,为什么用xp。 作为一个很早就接触 计算机的人,xp和dos充满着曾经的回忆。windows系统其实一直都是差不多的。    

本文由职坐标整理并发布,希望对同学们学习Python有所帮助,更多内容请关注职坐标编程语言Python频道!

本文由 @小标 发布于职坐标。未经许可,禁止转载。
喜欢 | 1 不喜欢 | 0
看完这篇文章有何感觉?已经有1人表态,100%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved

208小时内训课程