20190823 变量

一、变量

1、什么是变量

变量是会变化的量

2、为什么要有变量

计算机需要一种概念来描述事物

3、定义变量

如何在python中定义变量? 直接赋值 =

name='nick'
age=10
print(age)

4、变量的组成

1.变量名

变量名用来引用变量值,不需要定义变量

2.赋值符号

赋值给变量

3.变量值

存放数据,用来表达数据的状态

5、变量名的规范

  1. 变量值有意义

  2. 字母下划线数字组合,变量第一个字符不是数字

  3. 关键字不能声明为变量

    关键字

['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']

6、变量名的两种风格

  1. 驼峰体

    AgeOfNick=19

  2. 下划线(推荐)

age_of_nick

二、pycharm的使用与快捷键

1.设置

file --》 settings --》 editor --》general --》 change font size 。。。。

file --》 settings --》 editor --》font --》 修改默认字体大小

file --》 settings --》 editor --》color Scheme --》 python --》monokai (主题的配置)

file --》 settings --》 editor --》 general --》 code completion --》case sensitive completion --》 None 不区分大小写

2快捷键

ctrl + v 粘贴

ctrl + c 复制

ctrl + a 全选

ctrl + x 剪切

ctrl + y 删除整行

ctrl + backspace 删除一个单词

shift + enter 换行

ctrl + f 搜索 --》 match case 匹配大小写;words 匹配单词(以空格区分单词)

ctrl + d 向下复制

ctrl + shift + r 全局搜索

shift + F10 运行上一次运行的文件

ctrl + shift + f10 运行当前文件

home键与end键对应行首行尾

ctrl+home 整个代码的起始

三、python-turtle

利用turtle(海龟)库可以绘制各种你想要的的图形,是turtle绘图体系的Python实现

1.蟒蛇绘制代码详解

import turtle #调用turtle库
turtle.setup(650, 350, 200, 200) #turtle画布大小设置 长650宽350,画布位置200,200(位于屏幕左上角)
turtle.penup() #画笔抬起
turtle.fd(-250) #画笔前进-250(即后退250)
turtle.pendown() #画笔落下
turtle.pensize(25) #设置画笔尺寸为25
turtle.pencolor("purple") #设置画笔颜色
turtle.seth(-40) #更改画笔前进角度(绝对角度)

for i in range(4):
turtle.circle(40, 80) #画圆,半径40,角度80
turtle.circle(-40, 80)
turtle.circle(40, 80/2)

turtle.fd(40) #画笔前进-250(即后退250)
turtle.circle(16, 180) #画圆,半径40,角度80
turtle.fd(40 * 2/3) #前进40*2/3距离
turtle.done() #保留画布

2.基础指令

import turtle #调用库

turtle.speed(4) 运行速度

turtle.setup(800,600) 默认画布大小

turtle.done()

空间布局 隐式

turtle.goto(100,100) # 到达某一个点

turtle.goto(-100,-100) # 到达某一个点

旋转

turtle.seth(40) # 绝对

turtle.left(30) # 相对当前的角度而言旋转

turtle.seth(0)

turtle.right(90)

颜色体系

turtle.pencolor('red') # 画笔的颜色#

turtle.colormode(255) 255 RGB模式

turtle.pencolor(255,0,255) # 画笔的颜色

turtle.colormode(1)

turtle.pencolor(1,0,1) 101模式

画笔大小

turtle.pensize(10) # 控制画笔大小

控制画笔前进

turtle.forward(100)

turtle.fd(100)

turtle.bk(200)

turtle.circle(20,180)

填充颜色

turtle.fillcolor('yellow')

turtle.begin_fill()

turtle.circle(20)

turtle.end_fill()

控制画笔

turtle.penup() # 抬笔 trutle.pu()

turtle.pendown() # 落笔turtle.done()

3.画鹅

海龟

代码:

import turtle
t=turtle
turtle.speed(10)
t. setup(800,600)

#画头

turtle.penup()
turtle.goto(0,100)
turtle.pendown()
turtle.pensize(20)
turtle.fillcolor('black')
turtle.begin_fill()
turtle.circle(80,360)
turtle.end_fill()

#画肚子
turtle.up()
turtle.goto(-70,130)
# turtle.pencolor("red")   #找画笔
turtle.seth(-125)
turtle.pendown()
turtle.pensize(10)
turtle.circle(300,60)
turtle.up()

turtle.goto(70,130)
# turtle.pencolor("red")
turtle.down()
turtle.circle(-320,60)
# turtle.pencolor("red")
turtle.seth(-180)
turtle.circle(-450,18)


#画脚
turtle.up()
turtle.pencolor("yellow")

turtle.seth(-100)
turtle.pendown()
turtle.fillcolor("yellow")
turtle.begin_fill()
turtle.fd(50)
turtle.seth(30)
turtle.fd(63)
turtle.end_fill()



turtle.seth(0)
turtle.up()

turtle.fd(50)
turtle.seth(-70)
turtle.pendown()
turtle.fillcolor("yellow")
turtle.begin_fill()
turtle.fd(50)
turtle.seth(60)
turtle.fd(50)
turtle.end_fill()
turtle.up()

#画手

turtle.goto(125,30)
turtle.down()
turtle.pencolor("black")
turtle.seth(-65)
turtle.pensize(50)
turtle.fd(100)

turtle.up()
turtle.goto(-135,30)
turtle.down()
turtle.seth(-120)
turtle.fd(100)
turtle.up()

#围巾
turtle.goto(-70,120)
turtle.seth(-60)
turtle.down()
turtle.pencolor("red")
turtle.pensize(20)
turtle.circle(80,125)

#画眼
turtle.up()
turtle.goto(-20,190)
turtle.down()
turtle.pencolor("white")
turtle.pensize(3)
turtle.fillcolor('white')
turtle.begin_fill()
turtle.circle(20,360)
turtle.end_fill()


turtle.up()
turtle.goto(60,190)
turtle.down()
turtle.fillcolor('white')
turtle.begin_fill()
turtle.circle(20,360)
turtle.end_fill()

#画眼珠子

turtle.pencolor("black")
turtle.up()
turtle.goto(40,200)
turtle.down()
turtle.pensize(3)
turtle.circle(1,360)

turtle.up()
turtle.goto(-40,200)
turtle.down()
turtle.circle(1,360)


#画嘴
turtle.up()
turtle.goto(-35,160)
turtle.down()
turtle.pencolor("yellow")
turtle.seth(0)
turtle.fillcolor('yellow')
turtle.begin_fill()
turtle.fd(80)
turtle.seth(-145)
turtle.fd(50)
turtle.seth(145)
turtle.fd(50)
turtle.end_fill()

turtle.up()
turtle.goto(200,200)


turtle.done()
posted @ 2019-08-23 19:23  fwzzz  阅读(208)  评论(0编辑  收藏  举报