zoukankan      html  css  js  c++  java
  • Ubuntu Python2 和 Python3 共存 切换

    例如 你写了代码
    创建一个文件 在终端

    vim test.py
    

    然后写入代码

    print “hello world"
    

    接着运行代码

    python test.py
    

    会输出

    hello world
    

    这个就是系统默认用了python2 来运行python代码
    如果想用python3来解释这个代码文件
    可以这样运行

    python3 test.py
    

    但是我们在文件里的写的代码是不能在python3的解释器里运行成功的
    会输出

     File "test.py", line 12
        print "hello world"
                          ^
    SyntaxError: Missing parentheses in call to 'print'
    

    这是因为print函数在python2和python3中的语法不同
    需要把这个函数修改为

    print("hello world")
    

    这样再次运行

    python3 test.py
    

    输出

    hello world
    
  • 相关阅读:
    Linux文件及目录查找
    英语单词independent
    英语单词omitting
    英语单词deploy
    英语单词debug
    线程
    进程
    操作系统历史
    分布式爬虫
    爬虫基础
  • 原文地址:https://www.cnblogs.com/vercont/p/10210222.html
Copyright © 2011-2022 走看看