查看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. 数据分析库之Numpy

    Numpy get started NumPy中我们要学习的核心其实就是一个 ndarray n多 d dimension 维度 array数组 多维数组 创建一个ndarray的几种方法 impor ...

  2. 3. Longest Substring Without Repeating Characters无重复字符的最长子串

    网址:https://leetcode.com/problems/longest-substring-without-repeating-characters/ 显然采用sliding window滑 ...

  3. 第5天(半天)【shell编程初步、grep及正则表达式】

    第5天(半天)[shell编程初步.grep及正则表达式] shell编程初步(01)_recv shell脚本:文本文件 #!:/bin/bash #!:/usr/bin/python #!:/us ...

  4. AIX中PV,VG,LV及FS常用相关命令

    1.PV常用相关命令 1)lsdev:列出ODM(Object Data Manager)中的设备. 2)chdev:修改一个AIX设备的属性. 3)mkdev:创建一个AIX设备. 4)chpv:修 ...

  5. centos 7 安装iptables防火墙

    firewalle: 开启6379端口和16379端口 [root@localhost ~]# firewall-cmd --zone=public --add-port=6379/tcp --per ...

  6. Forth 输入流处理

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  7. VSTO:使用C#开发Excel、Word【17】

    使用Range对象Range对象表示电子表格中的单元格范围.范围可以包含一个单元格,多个连续的单元格,甚至多个不连续的单元格.您可以在Excel中选择时按住Ctrl键选择多个不连续的单元格. 获取特定 ...

  8. 第八节 多态和Object类

    多态的定义:某一类事物的多种存在形态 例子:学生类:包含学生A和学生B 学生A对象对应的类型是学生A类型:StudentA studentA = new StudentA; Student stude ...

  9. Alpha冲刺7

    前言 队名:拖鞋旅游队 组长博客:https://www.cnblogs.com/Sulumer/p/10013652.html 作业博客:https://edu.cnblogs.com/campus ...

  10. Linux平台网络配置-----C语言

    上一期我们已经介绍了VM虚拟机安装CentOS 7系统的步骤过程,这次就来看看使用Linux对初学者有什么障碍? 零基础学习C语言---Linux平台配置网络 用VM虚拟机启动Linux系统时出现的问 ...