目录
(1)注意的是字符串型的问题:字符串中有单引号''和双引号""
一.python运行环境
运行Python
安装成功后,打开命令提示符窗口cmd,敲入python后,会出现两种情况:
情况一:
┌────────────────────────────────────────────────────────┐ │Command Prompt - □ x │ ├────────────────────────────────────────────────────────┤ │Microsoft Windows [Version 10.0.0] │ │(c) 2015 Microsoft Corporation. All rights reserved. │ │ │ │C:\> python │ │Python 3.8.x ... │ │[MSC v... 64 bit (AMD64)] on win32 │ │Type "help", "copyright", "credits" or "license" for mor│ │information. │ │>>> _ │ │ │ │ │ └────────────────────────────────────────────────────────┘
看到上面的画面,就说明Python安装成功!
你看到提示符>>>
就表示我们已经在Python交互式环境中了,可以输入任何Python代码,回车后会立刻得到执行结果。现在,输入exit()
并回车,就可以退出Python交互式环境(直接关掉命令行窗口也可以)。
情况二:得到一个错误:
┌────────────────────────────────────────────────────────┐ │Command Prompt - □ x │ ├────────────────────────────────────────────────────────┤ │Microsoft Windows [Version 10.0.0] │ │(c) 2015 Microsoft Corporation. All rights reserved. │ │ │ │C:\> python │ │'python' is not recognized as an internal or external co│ │mmand, operable program or batch file. │ │ │ │C:\> _ │ │ │ │ │ │ │ └────────────────────────────────────────────────────────┘
这是因为Windows会根据一个Path
的环境变量设定的路径去查找python.exe
,如果没找到,就会报错。如果在安装时漏掉了勾选Add Python 3.8 to PATH
,那就要手动把python.exe
所在的路径添加到Path中。
2.在正式编写第一个Python程序前,我们先复习一下什么是命令行模式和Python交互模式。
命令行模式
在Windows开始菜单选择“命令提示符”,就进入到命令行模式,它的提示符类似C:\>
:
┌────────────────────────────────────────────────────────┐ │Command Prompt - □ x │ ├────────────────────────────────────────────────────────┤ │Microsoft Windows [Version 10.0.0] │ │(c) 2015 Microsoft Corporation. All rights reserved. │ │ │ │C:\> _ │ │ │ │ │ │