一、变量
(1)、命名规则
1、不能是python关键词
关键词列表
| if | elif | white | |
| input | else | def | int |
| float | str | inimport | try |
| class | pass | True | False |
2、限定字符
限定字符列表
| a-z | A-Z | 0-9 | 以及下划线 |
3、区分大小写
所以hello和HELLO是不同的变量名
(2)、语法
变量名 = 变量
(3)、变量的类型
类型列表
| int | float | bool | string |
| list | tuple | dictionary |
小知识:字符串类型要加引号
二、print函数
语法:print(x)
x为一个变量或数字、字符串
最后
送大家一个小礼物,复制以下代码到python,有惊喜!
注意是表白代码:
# -*- coding: utf-8 -*-
import turtle
import random
import time
my_name=input("输入你喜欢的人:")
abcd=' '
my_name = abcd+my_name
turtle.setup(1000,900)
#turtle.pencolor('red')
turtle.pensize(5)
turtle.penup()
turtle.goto(0,300)
turtle.fillcolor('red')
turtle.begin_fill()
turtle.pendown()
turtle.left(90)
turtle.left(45)
turtle.circle(230,180)
turtle.goto(0,-350)
turtle.goto(330,-25)
turtle.left(90)
turtle.circle(230,180)
turtle.end_fill()
turtle.fillcolor('black')
my_name_z = len(my_name)
my_name_z=my_name_z//2
my_name_z=my_name_z*60
my_name_z=0-my_name_z
turtle.pencolor('black')
turtle.penup()
turtle.goto(my_name_z,-100)
turtle.pendown()
turtle.write(my_name,font=('Arial',80,'normal'))
turtle.penup()
turtle.goto(-300,0)
turtle.pendown()
turtle.write('I LOVE YOU',font=('Arial',80,'normal'))
time.sleep(1)
turtle.reset()
turtle.speed(0)
turtle.penup()
turtle.goto(0,300)
turtle.pendown()
turtle.write('520',font=('Arial',20,'normal'))
abcdefg=520
abcdefg_='520'
_abcdefg=1
_abcdefg_='1'
while abcdefg>0:
a = random.randint(-400, 400)
b = random.randint(-400, 400)
turtle.penup()
turtle.goto(a,b)
turtle.pendown()
turtle.write(my_name+_abcdefg_)
abcdefg=abcdefg-1
abcdefg_=str(abcdefg)
_abcdefg=_abcdefg+1
_abcdefg_=str(_abcdefg)
time.sleep(2)
turtle.reset()
turtle.penup()
turtle.goto(-200,0)
turtle.pendown()
turtle.write('5201314',font=('Arial',80,'normal'))
ab=5201314
turtle.speed(0)
while ab>0:
a = random.randint(-400, 400)
b = random.randint(-400, 400)
turtle.penup()
turtle.goto(a,b)
turtle.pendown()
turtle.write('5201314')
ab=ab-1
turtle.done()
本文介绍了Python编程中变量的命名规则,包括避免使用保留字、字符限制和区分大小写。此外,还详细讲解了print函数的用法,并通过turtle库实现了一个简单的表白动画。
69万+





