Python2.7与3.6的一些区别】的更多相关文章

目录 Unicode编码 print函数 raw_input() 和 input( ) 不等运算符 数据类型 除法 map 和 filter Unicode编码 python2.x 解释器默认编码格式:ASCII,因此默认字符串不支持中文 python3.x 解释器默认编码格式:UTF-8 print函数 print "Hello World" # 2.x版本中格式 print("Hello World") # 3.x版本中格式 ''' 2.6版本已可以支持新的pr…
print函数 虽然print语法是Python 3中一个很小的改动,且应该已经广为人知,但依然值得提一下:Python 2中的print语句被Python 3中的print()函数取代,这意味着在Python 3中必须用括号将需要输出的对象括起来. 在Python 2中使用额外的括号也是可以的.但反过来在Python 3中想以Python2的形式不带括号调用print函数时,会触发SyntaxError. Python 2   1 2 3 4 print 'Python', python_ve…
2.7实现了一部分3的功能, 更早版本可能会稍稍涉及一点 首先是关键字的差别 python3.6 import keyword print(keyword.kwlist) ['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'im…
Python2 中可以直接使用reload(module)重载模块. Pyhton3中需要使用如下两种方式: 方式(1) >>> from imp >>> imp.reload(module) 方式(2) >>> from imp import reload >>> reload(module)…
Python3.x 中 input() 函数接受一个标准输入数据,返回为 string 类型. Python2.x 中 input() 相等于 eval(raw_input(prompt)) ,用来获取控制台的输入. raw_input() 将所有输入作为字符串看待,返回字符串类型.而 input() 在对待纯数字输入时具有自己的特性,它返回所输入的数字的类型( int, float ). 注意:input() 和 raw_input() 这两个函数均能接收 字符串 ,但 raw_input()…
1.type(1/2) python2是向下取整,0,为int:python3是正常除法,0.5,为float 2.…
Python2中unittest.TestSuite().addTest()的参数是这样的:unittest.TestSuite().addTest(TestFun("test_nam"));其中TestFun是继承于TestCase的类,test_name是里面的测试函数. 然后运行传list当参数: name_list=[TestFun("test_nam01"),TestFun("test_nam02"),TestFun("tes…
python2.x中的新类型类(New-style class)与python3.x的类一致,均继承object类,而不继承object的类称为经典类(classic class),而对于这两种类,一般实例属性截取函数(generic instance attribute interception methods)的行为有所不同,其在3.x和2.x的新类型类中,不再被__x__操作符重载函数名(operator overloading name)的内建操作调用,对于该操作符重载函数名的搜索直接在…
1.性能 Py3.0运行 pystone benchmark的速度比Py2.5慢30%.Guido认为Py3.0有极大的优化空间,在字符串和整形操作上可  以取得很好的优化结果.  Py3.1性能比Py2.5慢15%,还有很大的提升空间.    2.编码 Py3.X源码文件默认使用utf-8编码,这就使得以下代码是合法的:      >>> 中国 = 'china'      >>>print(中国)      china    3. 语法 1)去除了<>,…
好东西啊!!! Python 2 name Python 3 name urllib.urlretrieve() urllib.request.urlretrieve() urllib.urlcleanup() urllib.request.urlcleanup() urllib.quote() urllib.parse.quote()  urllib.quote_plus() urllib.parse.quote_plus() urllib.unquote() urllib.parse.unq…