python学习笔记

2022.6.14学习笔记

海龟作图

学会了常用的turtle模块的语句。

turtle语句功能
turtle.circle(i)以i为半径画圆
turtle.color(“”)画图的颜色
turtle.penup()抬笔
turtle.pendown()落笔
turtle.left()箭头向左转
turtle.right()箭头向右转
turtle.forword(i)前进i个像素

用海龟画图做五环

奥运五环: 在这里插入图片描述
下面展示代码段:

import turtle
t = turtle.Pen()

t.width(10)
t.color("blue")
t.circle(50)
t.penup()
t.goto(120,0)
t.pendown()
t.color("black")
t.circle(50)
t.penup()
t.goto(240,0)
t.pendown()
t.color("red")
t.circle(50)
t.penup()
t.goto(60,-50)
t.pendown()
t.color("yellow")
t.circle(50)
t.penup()
t.goto(180,-50)
t.pendown()
t.color("green")
t.circle(50)

对象和内存的含义

python中一切皆对象,3就是个对象,它拥有地址,类型和值的属性。a是个变量。执行a = 3之后,将3的地址传给了a,因此可以通过a查找到3的地址,所以此时a就是3。字符串同理。变量a等存放在栈中,对象3等存放在堆中。

a = 3
print(id(3))
print(id(a))
print(type(a))
print(type(3))
t = "你好"
print(id(t))
print(id("你好"))
print(type(t))
print(type("你好"))

运行结果
在这里插入图片描述

标识符的命名规则

只能以数字字母开头,后面可以是下划线。同时一些keywords不可以作为标识符命名。

['False', 'None', 'True', '__peg_parser__', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

变量的声明初始化以及回收机制

只有变量进行初始化之后才可以打印出变量,否则会显示错误。可以使用del语句删除变量,删除之后对象还在,python就会启动垃圾回收机制将对象回收掉。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

酸辣土豆丝2333

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值