python从入门到精通(3)----变量与print

本文介绍了Python编程中变量的命名规则,包括避免使用保留字、字符限制和区分大小写。此外,还详细讲解了print函数的用法,并通过turtle库实现了一个简单的表白动画。

一、变量

(1)、命名规则

1、不能是python关键词

关键词列表 

ifelifwhiteprint
inputelsedefint
floatstrinimporttry
classpassTrueFalse

2、限定字符

限定字符列表

a-zA-Z0-9以及下划线

3、区分大小写

所以hello和HELLO是不同的变量名

(2)、语法

变量名 = 变量

(3)、变量的类型

类型列表

int floatboolstring
listtupledictionary

 

小知识:字符串类型要加引号

二、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()
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值