【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 ...
随机推荐
- hdu 3695 10 福州 现场 F - Computer Virus on Planet Pandora 暴力 ac自动机 难度:1
F - Computer Virus on Planet Pandora Time Limit:2000MS Memory Limit:128000KB 64bit IO Format ...
- iptables Configuration
iptables usage: Add Rules: iptables -I INPUT -p tcp --dport -j ACCEPT iptables -I INPUT -p tcp --dpo ...
- tortoiseGIT保存用户名密码
虽然GIT可以使用SSH来免去输入用户名密码的麻烦,但是更多的人我相信还是比较喜欢使用tortoiseGIT. 使用HTTP模式的代码库可以通过保存用户名密码的方式来免去重复输入的麻烦. 首先安装gi ...
- spring注解-@Autowired。@Resource。@Service
Spring的@Autowired注解.@Resource注解和@Service注解 什么是注解 传统的Spring做法是使用.xml文件来对bean进行注入或者是配置aop.事物,这么做有两个缺点: ...
- [BZOJ3162]独钓寒江雪
bzoj description 你要给一个树上的每个点黑白染色,要求白点不相邻.求本质不同的染色方案数. 两种染色方案本质相同当且仅当对树重新标号后对应节点的颜色相同. \(n\le 5\times ...
- 【传输协议】发送https请求,由于客户端jdk版本过高,服务端版本低。导致异常:javax.net.ssl.SSLHandshakeException: Server chose SSLv3, but that protocol version is not enabled or not supported by the client.
本地环境jdk为1.8,服务器使用jdk版本未知.但发送https请求,抛出如下异常,解决方案. 一:发送异常内容如下 javax.net.ssl.SSLHandshakeException: Ser ...
- Hibernate环境搭建+struts整合
说明:本文档,是和struts2+hibernate的整合示例. lib下还有struts2的jar包,本示例没有显示.struts2的搭建参考struts2的环境搭建 一下载hibernate的ja ...
- Testng优势
选择Testng的理由: 1.可指定执行顺序, dependsOnMethods 属性来应对测试的依赖性问题. 2.·参数化1:轻轻松松从XML中得到参数 @BeforeClass public vo ...
- Pandas Timestamp 和 python 中 datetime 的互相转换
Pandas 的Timestamp 和 python 的 datetime, 这是两种不同的类型. 它们之间可以互相转换. refer to: https://www.jianshu.com/p/ ...
- ballerina 学习二十三 扩展ballerina
扩展ballerina 目前有三种方式: 扩展client connector的包 (数据库访问,基础设施,api) 扩展server listenner 绑定为不同的协议 添加新的注解到baller ...