查看Python版本

# python -V

Python2.7.5是centos7中默认安装的Python

[root@localhost ~]# python -V
Python 2.7.
[root@localhost ~]# python
Python 2.7. (default, Oct , ::)
[GCC 4.8. (Red Hat 4.8.-)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> #输入exit()或者ctrl+d退出Python的交互式编程模式

查看Python在Linux中的安装位置

# whereis python

[root@localhost ~]# whereis python
python: /usr/bin/python2. /usr/bin/python /usr/lib/python2. /usr/lib64/python2. /etc/python /usr/include/python2. /usr/share/man/man1/python..gz
[root@localhost ~]#

升级Python2.x到Python3.x请参照另一篇博客

https://www.cnblogs.com/djlsunshine/p/10689591.html

编写第一个Python实例“hello Word”

# vi hello.py

[root@localhost ~]# vi hello.py
#!/usr/bin/python
print("Hello, World!");

使用Python命令执行该脚本文件

# python hello.py

[root@localhost ~]# python hello.py
Hello, World!

除法运算

Python中的除法有两个运算符

“/”和“//”

在Python2.x中,整数相除的结果是一个整数,把小数部分完全忽略掉

浮点数除法会保留小数点的部分得到一个浮点数的结果

[root@localhost ~]# python2
Python 2.7. (default, Nov , ::)
[GCC 4.8. (Red Hat 4.8.-)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> / >>> 1.0 / 2.0
0.5
>>>

在Python3.x中,“/”除法不再这么做了,对于整数之间的相除,结果也会是浮点数

[root@localhost ~]# python3
Python 3.6. (default, Apr , ::)
[GCC 4.8. (Red Hat 4.8.-)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> /
0.5
>>>

“//”除法叫做floor除法,会对除法的结果自动进行一个floor操作,在python2.x和python3.x中是一致的。

python2:
>>> - // 2
-
>>>
python3:
>>> - // 2
-
>>>

注意:并不是舍弃小数部分,而是执行floor操作,如果要截取小数部分,那么需要使用math模块的trunc函数

python3:
>>> import math
>>> math.trunc(/) >>> math.trunc(-/) >>>

end

Python第一天:python2.x和python3.x的区别的更多相关文章

  1. 【python系列】python2.x和python3.x的区别

    刚接触python使用的是python2.x的书籍,但是发现python3.x和python2.x有不小的区别,以下做一些记录 性能 Py3.0运行 pystone benchmark的速度比Py2. ...

  2. python面试题Python2.x和Python3.x的区别

    所属网站分类: 面试经典 > python 作者:外星人入侵 原文链接: http://www.pythonheidong.com/blog/article/22/ 来源:python黑洞网 w ...

  3. python之路-python2.x与python3.x区别

    Python崇尚优美.清晰.简单,是一个优秀并广泛使用的语言. Python2.x 与 Python3.x的区别: python2.x:源码混乱,重复代码较多,冗余. python3.x:源码规范,崇 ...

  4. python大法好——Python2.x与3​​.x版本区别

    python大法好——Python2.x与3​​.x版本区别 Python的3​​.0版本,常被称为Python 3000,或简称Py3k.相对于Python的早期版本,这是一个较大的升级. 为了不带 ...

  5. python2.x和python3.x的区别

    一.python2.x和python3.x中raw_input( )和input( )区别 1.在Python2.x中raw_input( )和input( ),两个函数都存在,其中区别为 raw_i ...

  6. Python2.x与Python3.x的区别

    这个星期开始学习Python了,因为看的书都是基于Python2.x,而且我安装的是Python3.1,所以书上写的地方好多都不适用于Python3.1,特意在Google上search了一下3.x和 ...

  7. python2.x 与 python3.x的区别

    从语言的源码角度: python2.x 的源码书写不够规范,且源码有重复,代码的复用率不高; python3.x 的源码清晰.优美.简单 从语言的特性角度: python2.x 默认为ASCII字符编 ...

  8. 转:python2.x 和 python3.x的区别

    注:本文的原文地址为Key differences between Python 2.7.x and Python 3.x 许多 Python 初学者想知道他们应该从 Python 的哪个版本开始学习 ...

  9. Python语言基础-语法特点、保留字与标识符、变量、基本数据类型、运算符、基本输入输出、Python2.X与Python3.X区别

    Python语言基础 1.Python语法特点 注释: 单行注释:# #注释单行注释分为两种情况,例:第一种#用于计算bim数值bim=weight/(height*height)第二种:bim=we ...

随机推荐

  1. localStorage、sessionStorage用法以及区别

    设置: sessionStorage.setItem("key", "value");localStorage.setItem("site" ...

  2. Java中如何设置表格处于不可编辑状态

    代码片段如下: 这样的话就可以将表格设置为不可编辑状态

  3. 2015-10-15 css3

    图片模糊效果 <img id ="img1" src="image/免费学PS.jpg" style="-webkit-filter: blur ...

  4. npm 设置和取消代理配置

    设置代理npm config set proxy=http://127.0.0.1:8087npm config set registry=http://registry.npmjs.org12关于h ...

  5. 老司机浅谈linux系统学习技巧

    Linux起源于20世纪70年代,是一种优秀的操作系统系统.初次接触到linux这个系统是在大学期间,这样才发现除了windows外的另外一个有趣系统.开始抱着好奇的心态去了解,随着深入学习,笔者被它 ...

  6. LeetCode 47 全排列II

    题目: 给定一个可包含重复数字的序列,返回所有不重复的全排列. 示例: 输入: [1,1,2] 输出: [ [1,1,2], [1,2,1], [2,1,1] ] 解题思路: 与上一题相比,这题多了一 ...

  7. sed语法2

    sed命令是一个面向字符流的非交互式编辑器,也就是说sed不允许用户与它进行交互操作.sed是按行来处理文本内容的.在shell中,使用sed来批量修改文本内容是非常方便的. sed命令的选项 sed ...

  8. [LeetCode&Python] Problem 844. Backspace String Compare

    Given two strings S and T, return if they are equal when both are typed into empty text editors. # m ...

  9. Dijkstra(迪杰斯特拉)模板

    直接将模板封装在结构体里面. struct Edge{ int from,to,dist; Edge(int u, int v,int d): from(u),to(v),dist(d){} }; s ...

  10. 同一台电脑中同时安装oracle database 服务器端和oracle client 客户端时注意

    如果在一台电脑中同时安装oracle的客户端和服务器端软件, 一定要先安装oracle database 服务端,并进行相应的配置 listener.ORA. 然后再去安装oracle client ...