【320】Python 2.x 与 3.x 的区别
通过代码移植的报错进行梳理!
1. print 函数的区别
Python 2.x 中可以加空格或者括号,但是 Python 3.x 只能是括号的
# Python 2.x
>>> print "processing..."
processing...
>>> print("processing...")
processing... # Python 3.x
>>> print("processing...")
processing...
2. raw_input 与 input 函数
Python 2.x 中 raw_input 与 Python 3.x 中 input 函数类似,而 Python 2.x 中的 input 函数接收数字或者带引号字符串
# Python 2.x
>>> a = raw_input("Value: ")
Value: Alex
>>> a
'Alex'
>>> b = input("Value: ")
Value: "Alex"
>>> b
'Alex' # Python 3.x
>>> a = input("Value: ")
Value: Alex
>>> a
'Alex'
参考:python2.x和python3.x中raw_input( )和input( )区别
3. Tkinter 模块
Python 2.x 为 Tkinter,但是 Python 3.x 为 tkinter(小写)
# Python 2.x
>>> import Tkinter # Python 3.x
>>> import tkinter
4. 除法运算符
Python 2.x 中 /、// 均为整除,但是 Python 3.x 中 / 表示除以,// 表示整除
# Python 2.x
>>> 77/60
1
>>> 77//60
1 # Python 3.x
>>> 77/60
1.2833333333333334
>>> int(77/60)
1
>>> 77//60
1
5. cmd 默认 Python 版本
需要通过修改环境变量来切换 Python 2.x 和 Python 3.x
参考:如何快速切换Python运行版本,如何选择Python版本
【320】Python 2.x 与 3.x 的区别的更多相关文章
- python _、__和__xx__的区别
python _.__和__xx__的区别 本文为译文,版权属于原作者,在此翻译为中文分享给大家.英文原文地址:Difference between _, __ and __xx__ in Pytho ...
- python中import和from...import...的区别
python中import和from...import...的区别: 只用import时,如import xx,引入的xx是模块名,而不是模块内具体的类.函数.变量等成员,使用该模块的成员时需写成xx ...
- 转发 python中file和open有什么区别
python中file和open有什么区别?2008-04-15 11:30地痞小流氓 | 分类:python | 浏览3426次python中file和open有什么区别?都是打开文件,说的越详细越 ...
- Python新式类与经典类的区别
1.新式类与经典类 在Python 2及以前的版本中,由任意内置类型派生出的类(只要一个内置类型位于类树的某个位置),都属于“新式类”,都会获得所有“新式类”的特性:反之,即不由任意内置类型派生出的类 ...
- Python import与from import使用及区别介绍
Python程序可以调用一组基本的函数(即内建函数),比如print().input()和len()等函数.接下来通过本文给大家介绍Python import与from import使用及区别介绍,感 ...
- 【转】python类中super()和__init__()的区别
[转]python类中super()和__init__()的区别 单继承时super()和__init__()实现的功能是类似的 class Base(object): def __init__(se ...
- Python新式类和经典类的区别
@Python新式类和经典类的区别 class ClassicClass(): pass class NewStyleClass(object): pass x1 = ClassicClass() x ...
- Python3.x:python: extend (扩展) 与 append (追加) 的区别
Python3.x:python: extend (扩展) 与 append (追加) 的区别 1,区别: append() 方法向列表的尾部添加一个新的元素.只接受一个参数: extend()方法只 ...
- Python中str()与repr()函数的区别——repr() 的输出追求明确性,除了对象内容,还需要展示出对象的数据类型信息,适合开发和调试阶段使用
Python中str()与repr()函数的区别 from:https://www.jianshu.com/p/2a41315ca47e 在 Python 中要将某一类型的变量或者常量转换为字符串对象 ...
- python 基础-文件读写'r' 和 'rb'区别
原文链接: python基础-文件读写'r' 和 'rb'区别 一.Python文件读写的几种模式: r,rb,w,wb 那么在读写文件时,有无b标识的的主要区别在哪里呢? 1.文件使用方式标识 'r ...
随机推荐
- 前序+中序->后序 中序+后序->前序
前序+中序->后序 #include <bits/stdc++.h> using namespace std; struct node { char elem; node* l; n ...
- 有效二叉查找树判断(java实现)
leetcode 原题 :(即判断二叉树是否为二叉查找树) Given a binary tree, determine if it is a valid binary search tree (BS ...
- 在pixi中使用你的自定义着色器
通过几天的学习,对openGL.shader有了一个大致的了解. 回到学习的初衷吧,在基于pixi.js重构D3项目的时候,因为精灵层级的问题,我得按照一定的先后顺序将不同类别的精灵添加到场景中去. ...
- 重启Tomcat还可以这样玩的哦
- 2017《Java技术》预备作业02
1.学习使用Git和码云托管代码 参考资料:如何使用Git和码云 安装Git 在码云注册账号,新建项目,名称为Java-CS01(02)XXX, 一班为CS01,二班为CS02,后三位或两位为姓名缩写 ...
- Java与WCF交互(二):WCF客户端调用Java web service【转】
原文:http://www.cnblogs.com/downmoon/archive/2010/08/25/1807982.html 在上篇< Java与WCF交互(一):Java客户端调用WC ...
- 使用defined和require引入js
define(function(require, exports, module) { var ceshiTwo = { dataCeshi:[1,2,3,4,5], arrCeshi:functio ...
- 排列组合算法(基于c++实现)
排列 全排列是将一组数按一定顺序进行排列,如果这组数有n个,那么全排列数为n!个.现以{1, 2, 3}为例说明如何编写全排列的递归算法 第一层S1表示第一个数分别与第1.2.3个数交换位置,如123 ...
- 【转】VC++ 也有 Refactoring 功能了
原文网址:http://blog.csdn.net/yapingxin/article/details/18923095 分类: C++2014-02-04 14:00 2688人阅读 评论(0) 收 ...
- USACO 2016 February Contest, Gold解题报告
1.Circular Barn http://www.usaco.org/index.php?page=viewproblem2&cpid=621 贪心 #include <cstd ...