美文网首页
2019-07-28python练习day01

2019-07-28python练习day01

作者: 聚散本匆匆 | 来源:发表于2019-07-28 20:30 被阅读0次

python练习day01

初识Python

从终端运行Python程序

确认Python的版本

可以Windows的命令行提示符中键入下面的命令。

python --version

或者是在Linux或macOS系统的终端中键入下面的命令。

python3 --version

当然也可以先输入python或python3进入交互式环境,再执行以下的代码检查Python的版本。

import sys

print(sys.version_info)

print(sys.version)

可以通过安装Jupyter工具并运行名为notebook的程序在浏览器窗口中进行交互式代码编写操作。

pip install jupyter

pip3 intall jupyter

然后执行下面的命令:

jupyter notebook

练习

在Python交互环境中查看下面的代码结果,并试着将这些内容翻译成中文。

import this

说明:当前键入上面的命令后会在交互式环境中看到如下所示的输出,这段内容被称为“Python之禅”,里面讲述的道理不仅仅适用于Python,也适用于其他编程语言。

The Zen of Python, by Tim Peters

Beautiful is better than ugly.

Explicit is better than implicit.

Simple is better than complex.

Complex is better than complicated.

Flat is better than nested.

Sparse is better than dense.

Readability counts.

Special cases aren't special enough to break the rules.

Although practicality beats purity.

Errors should never pass silently.

Unless explicitly silenced.

In the face of ambiguity, refuse the temptation to guess.

There should be one-- and preferably only one --obvious way to do it.

Although that way may not be obvious at first unless you're Dutch.

Now is better than never.

Although never is often better than *right* now.

If the implementation is hard to explain, it's a bad idea.

If the implementation is easy to explain, it may be a good idea.

Namespaces are one honking great idea -- let's do more of those!

学习使用turtle在屏幕上绘制图形。

说明:turtle是Python内置的一个非常有趣的模块,特别适用于让小朋友体会什么是编程,它最早是Logo语言的一部分,Logo语言是Wally Feurzig和Seymour Papert在1966发明的编程语言.

import turtle

#画一个正方形

turtle.pensize(4)  #字体大小

turtle.pencolor('blue') #颜色

turtle.forward(100) #移动方向向前移动100个单位

turtle.right(90) #右转指定角度

turtle.forward(100)  

turtle.right(90)

turtle.forward(100)

turtle.right(90)

turtle.forward(100)

turtle.mainloop() #主循环

相关文章

网友评论

      本文标题:2019-07-28python练习day01

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