table of Contents
I was the third in a blog
First, acquaintance Python
1. Variables
- Variable is a variable quantity, attributes used to describe certain things. It is to describe the nature and role of receiving variable values
- Define a variable way:
Variable name = variable value
Variable name rules:
- Variable names must be meaningful
- Variable names with letters, numbers and underscores.
- Variable names can not be named keyword
Two types of variables name representation:
Underline and hump body (to solve the problem of multiple words variable name)
The concept of variables are provided by Python, if you do not run the program code, there is no variable.
2. Comment
The purpose of the comment:
1. 2. failure code so that the back front of the interpreted code
- Notes divided into: single-line comments, multiline comments.
- The method of single-line comments as follows: first add a line == == #
- A method for multi-line comments: == '' '== (footnotes) ==' '' ==, i.e. before and after addition of each individual single quotes 3
3.turtle library
The use of turtle drawing:
import turtleturtle.setup(1000,800)turtle.position()turtle.pensize(2)turtle.pencolor("yellow")turtle.pu()turtle.fd(200)turtle.pd()turtle.seth(90)turtle.circle(200,180)#画上半部分轮廓turtle.circle(300,20)#画左下半部分轮廓turtle.fd(50)turtle.circle(150,80)turtle.pu()#调整光标位置turtle.goto(0,0)turtle.seth(0)turtle.fd(200)turtle.seth(90)turtle.pd()turtle.circle(300,-20)#画右下半部分轮廓turtle.fd(-50)turtle.circle(150,-80)turtle.pu()#画左眼turtle.goto(-120,80)turtle.pd()turtle.seth(0)turtle.pencolor("green")turtle.pensize(3)for i in range(5): turtle.fd(7) turtle.right(5)turtle.seth(0)for i in range(5): turtle.fd(7) turtle.left(5)turtle.pu()turtle.goto(-90,50)turtle.seth(0)turtle.pd()turtle.begin_fill()turtle.colormode(255)turtle.color(255,0,0)turtle.circle(20)turtle.end_fill()turtle.pu()#画右眼turtle.goto(55,80)turtle.pd()turtle.seth(0)turtle.pencolor("green")turtle.pensize(3)for i in range(5): turtle.fd(7) turtle.right(5)turtle.seth(0)for i in range(5): turtle.fd(7) turtle.left(5)turtle.pu()turtle.goto(90,50)turtle.seth(0)turtle.pd()turtle.begin_fill()turtle.colormode(255)turtle.color(255,0,0)turtle.circle(20)turtle.end_fill()turtle.pu()#画嘴turtle.pencolor("green")turtle.pensize(4)turtle.goto(-60,-150)turtle.pd()turtle.fd(120)turtle.seth(-150)turtle.fd(70)turtle.seth(150)turtle.fd(70)turtle.pu()#画头发turtle.goto(0,200)turtle.seth(0)turtle.pensize(2)turtle.pencolor("yellow")turtle.pd()turtle.circle(50,60)turtle.circle(-50,80)turtle.circle(50,80)turtle.circle(-50,80)turtle.color("red")#写字turtle.penup()turtle.goto(-130, -100)turtle.pendown()turtle.write("我变秃了、也变强了!!", font = ("Times", 20, "bold"))turtle.hideturtle()turtle.done()