Pycharm开发环境设置与熟悉。
练习基本输入输出:
print('你好,{}.'.format(name))
print(sys.argv)
库的使用方法:
import ...
from ... import ...
条件语句:
if (abs(pos()))<1:
break
循环语句:
for i in range(5):
while True:
函数定义:
def mygoto(x,y):
def drawjx(r):
综合练习:画一面五星红旗,将代码与运行截图发布博客交作业。
import turtle
def mygoto(x, y):
turtle.up()
turtle.goto(x, y)
turtle.down()
def drawstar(x):
turtle.begin_fill()
for i in range(5):
turtle.forward(x)
turtle.right(144)
turtle.end_fill()
turtle.setup(600,400,0,0)
turtle.color("yellow")
turtle.bgcolor("red")
turtle.fillcolor("yellow")
mygoto(-260,120)
drawstar(120)
mygoto(-120,160)
turtle.left(15)
drawstar(40)
mygoto(-80,120)
turtle.left(12)
drawstar(40)
mygoto(-80,60)
drawstar(40)
mygoto(-120,20)
turtle.left(30)
drawstar(40)
turtle.hideturtle()
turtle.done()
字符串练习:
http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html
取得校园新闻的编号
>>> url1 = 'http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html'
>>> url1[-14:-5]
'1027/8443'
https://docs.python.org/3/library/turtle.html
产生python文档的网址
http://news.gzcc.cn/html/xiaoyuanxinwen/4.html
产生校园新闻的一系列新闻页网址
练习字符串内建函数:strip,lstrip,rstrip,split,count,replace
用函数得到校园新闻编号
>>> url = 'http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html'
>>> print(url.rstrip('.html').split('_')[1])
1027/8443
用函数统计一歌词(文章、小说)中单词出现的次数,替换标点符号为空格,用空格进行分词。
>>> song = '''
There For You - Martin Garrix/Troye Sivan
Written by:Bea Miller/Brady Riley/Brett McLaughlin/Martin Garrix/Troye Sivan
I woke up pissed off today
And lately everyone feels fake
Somewhere I lost a piece of me
Smoking cigarettes on balconies
But I can't do this alone
Sometimes I just need a light
If I call you on the phone
Need you on the other side
So when your tears roll down your pillow like a river
I'll be there for you
I'll be there for you
When you're screaming but they only hear you whisper
I'll be loud for you
But you gotta be there for me too
But you gotta be there for me too
Last year took a toll on me
But I made it with you next to me
Around the world and back again
I hope you're waiting at the end
But I can't do this alone
Sometimes I just need a light
If I call you on the phone
Need you on the other side
So when your tears roll down your pillow like a river
I'll be there for you
I'll be there for you
When you're screaming but they only hear you whisper
I'll be loud for you
I'll be loud for you
I got you I promise
Let me be honest
Love is a road that goes both ways
When your tears roll down your pillow like a river
I'll be there for you
But you gotta be there for me too
But you gotta be there for me too
Boy I'm holding on to something
Won't let go of you for nothing
I'm running running just to keep my hands on you
There was a time that I was so blue
What I got to do to show you
I'm running running just to keep my hands on you
Running running just to keep my hands on you
Running running just to keep my hands on you
So I'm running running just to keep my hands on you
But you gotta be there for me too
But you gotta be there for me too
'''
>>> song.count('you')
38
>>> essay = '''
明月几时有?把酒问青天。不知天上宫阙,今夕是何年?我欲乘风归去,惟恐琼楼玉宇,高处不胜寒.起舞弄清影,何似在人间?转朱阁,低绮户,照无眠。不应有恨,何事长向别时圆?人有悲欢离合,月有阴晴圆缺,此事古难全。但愿人长久,千里共蝉娟。
'''
>>> essay.replace(',',' ').replace('。',' ').replace('?',' ')
'\n明月几时有 把酒问青天 不知天上宫阙 今夕是何年 我欲乘风归去 惟恐琼楼玉宇 高处不胜寒.起舞弄清影 何似在人间 转朱阁 低绮户 照无眠 不应有恨 何事长向别时圆 人有悲欢离合 月有阴晴圆缺 此事古难全 但愿人长久 千里共蝉娟 \n'
>>> essay1 = test.split('str = ' '')
>>> print(essay1)
['\n明月几时有?把酒问青天。不知天上宫阙、今夕是何年?我欲乘风归去,惟恐琼楼玉宇,高处不胜寒.起舞弄清影,何似在人间? 转朱阁,低绮户,照无眠。不应有恨、何事长向别时圆?人有悲欢离合,月有阴晴圆缺,此事古难全。但愿人长久,千里共蝉娟。\n']
>>>