
上QQ阅读APP看书,第一时间看更新
1.2 编写第一个Python程序
安装好Python程序后,接下来可以运行Python程序,并开始编写程序了。
1.2.1 使用IDLE运行Python程序

用IDLE运行Python程序
IDLE(集成开发环境)是Python的集成开发环境,它被打包为Python包装的可选部分,当安装好Python以后,IDLE就自动安装好了,不需要另外去安装。使用IDLE运行Python程序的方法如图1-3所示。

图1-3 IDLE开发环境

图1-3 IDLE开发环境(续)
1.2.2 实例:用IDLE编写第一个Python程序

编写第一个Python程序
接下来我们尝试用IDLE开发环境编写第一个Python程序,如图1-4所示。

图1-4 用IDLE编写第一个Python程序

图1-4 用IDLE编写第一个Python程序(续)

图1-4 用IDLE编写第一个Python程序(续)
1.2.3 实例:编写第一个交互程序

编写第一个交互程序
下面我们编写一个稍微复杂一点的程序。使用Input()函数编写一个请用户输入名字的程序。如图1-5所示。

图1-5 编写一个交互程序

图1-5 编写一个交互程序(续)

图1-5 编写一个交互程序(续)
提示
Input()函数可以让用户输入字符串,并存放到一个变量里,然后可以使用print()函数输出变量的值。
1.2.4 使用命令行工具运行Python程序
除了使用IDLE开发环境外,还可以命令行模式运行Python程序,如图1-6所示。

图1-6 使用命令行工具运行Python程序
1.2.5 实例:在命令行窗口中输出“我来了,Python”
在命令行中运行Python后,同样可以编写Python程序,如图1-7所示。

图1-7 用命令提示符编写程序