美文网首页
Python 0:python新特性

Python 0:python新特性

作者: Cc曹子恒 | 来源:发表于2018-04-15 17:27 被阅读0次

    相较于python2.6,python3.0的新特性

    print语句被print()函数取代了,可以使用关键字参数来替代老的print特殊语法。
    
    Old:print "The answer is", 2*2
    New: print("The answer is", 2*2)
    
    Old: print x,       #使用逗号结尾禁止换行
    New: print(x, end = "")     #使用空格代替换行
    
    Old:print       #输出新行
    New:print()     #输出新行
    
    Old:print >> sys.stderr, "fatal error"
    New: print("fatal error", file = sys.error)
    
    Old: print (x,y)        #输出repr((x,y))
    New: print((x,y))       #不同于print(x,y)!
    
    你可以自定义输出项之间的分隔符:print("There are <", 2**32, " > possibilities!", sep = "")
    输出结果是:There are <4294967296> possibilities!
    
    • 1/2返回浮点数,使用1//2能得到整数
    • 移除了 <>(不等号,使用 != 代替)

    相关文章

      网友评论

          本文标题:Python 0:python新特性

          本文链接:https://www.haomeiwen.com/subject/jktjkftx.html