PY练习
from turtle import * def position(x, y): up() goto(x, y) down() def drawstar(size, x, y): position(x, y) color('yellow') begin_fill() fillcolor('yellow') for i in range(5): forward(size) if size == 150: right(144) else: left(144) end_fill() bgcolor('red') speed(5) drawstar(150, -300, 160) drawstar(50, -180, 250) drawstar(50, -80, 200) drawstar(50, -80, 90) drawstar(50, -180, 10) hideturtle() done()
str1 ='Python!Python!Python' print(str1) print(str1[0]) print(str1[2:5]) print(str1[2:]) print(str1 * 2)
html1 = 'http://news.gzcc.cn/html/2018/xiaoyuanxinwen_0314/9024.html' print(html1[-14:-5], '\n ----------------------') html_end = '.html' html2 = 'https://docs.python.org/dev/library/' a = ['string', 'sys', 'turtle', 'os'] for g in a: html = html2 + str(g) + html_end print(html) print('\n ----------------------') new_html1 = 'http://news.gzcc.cn/html/2018/xiaoyuanxinwen/' for i in range(0, 11): new = new_html1 + str(i) + html_end print(new)
a = ' There is \n a python document \n ! is a good code!!!!' print(a.strip(), '\n ---------------------') print(a.lstrip(), '\n---------------------') print(a.rsplit(), '\n---------------------') print(a.count('!'), '\n---------------------') print(a.count('is'), '\n---------------------') print(a.split('\n'))