0


Python中的turtle.right()方法的用法示例

turtle模块以面向对象和面向过程的方式提供了turtle图形原语。因为它使用Tkinter来处理底层图形,所以它需要一个安装了Tk支持的Python版本。

turtle.right()

turtle.right()方法用于通过其参数值更改turtle的方向。它使turtle的头部朝一个方向移动。

语法如下:

  1. turtle.right(angle)

它接受的参数是angle {一个数字(整数或浮点数)}。因此, 它以角度单位向右转。 (单位默认为度, 但可以通过度()和弧度()函数进行设置。)角度方向取决于模式。

下面是上述方法的实现并带有一些示例:

范例1:

Python3

  1. # importing package
  2. import turtle
  3. # move the turtle forward by
  4. # 100 unit distance in the
  5. # direction of head of turtle
  6. turtle.forward( 100 )
  7. # change the direction of turtle
  8. # by 90 degrees to the right.
  9. turtle.right( 90 )
  10. # move the turtle forward by
  11. # 100 unit distance in the
  12. # direction of head of turtle
  13. turtle.forward( 100 )

输出:

范例2:

Python3

  1. # importing package
  2. import turtle
  3. # Loop for pattern
  4. for i in range ( 10 ):
  5. # move the turtle forward by
  6. # 100+variable unit distance
  7. # in the direction of head of turtle
  8. turtle.forward( 100 + 10 * i)
  9. # change the direction of turtle
  10. # by 90 degrees to the right.
  11. turtle.right( 90 )

输出:

首先, 你的面试准备可通过以下方式增强你的数据结构概念:Python DS课程。

更多Python开发相关内容请参考:lsbin - IT开发技术:https://www.lsbin.com/

查看以下更多Python相关的内容:

标签: python gui tkinter

本文转载自: https://blog.csdn.net/u014240783/article/details/115335868
版权归原作者 扯线木偶人 所有, 如有侵权,请联系我们删除。

“Python中的turtle.right()方法的用法示例”的评论:

还没有评论