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

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

 

turtle.right()

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

语法如下:

turtle.right(angle)

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

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

范例1:

Python3

# importing package
import turtle
  
  
# move the turtle forward by 
# 100 unit distance in the
# direction of head of turtle
turtle.forward( 100 )
  
# change the direction of turtle
# by 90 degrees to the right.
turtle.right( 90 )
  
# move the turtle forward by
# 100 unit distance in the 
# direction of head of turtle
turtle.forward( 100 )

输出:

范例2:

Python3

# importing package
import turtle
  
  
# Loop for pattern
for i in range ( 10 ):
    
   # move the turtle forward by 
   # 100+variable unit distance
   # in the direction of head of turtle
   turtle.forward( 100 + 10 * i)
    
   # change the direction of turtle
   # by 90 degrees to the right.
   turtle.right( 90 )

输出:

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

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

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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值