python include is not defined_讨论 - 廖雪峰的官方网站

由于 macOS 会保留 2.7 版本的 Python ,所以默认通过命令行运行「python」进入的是 2.7 版本

MBP ~ % python

WARNING: Python 2.7 is not recommended.

This version is included in macOS for compatibility with legacy software.

Future versions of macOS will not include Python 2.7.

Instead, it is recommended that you transition to using 'python3' from within Terminal.

Python 2.7.16 (default, Jun  5 2020, 22:59:21)

[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc- on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> name = input('please enter your name: ')

please enter your name: jimmy

Traceback (most recent call last):

File "", line 1, in

File "", line 1, in

NameError: name 'jimmy' is not defined

>>>

按照这个提示,安装 3 以上版本通过 python3 命令进入就不会有问题

MBP ~ % python3

Python 3.8.6 (default, Oct  8 2020, 14:06:32)

[Clang 12.0.0 (clang-1200.0.32.2)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> name = input('please enter your name: ')

please enter your name: jimmy

>>> print('hello,', name)

hello, jimmy

>>>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值