美文网首页Python四期爬虫作业
【Python爬虫】-第四期课后练习7

【Python爬虫】-第四期课后练习7

作者: 困困harper | 来源:发表于2017-08-19 16:45 被阅读7次
# coding:utf-8
import json
#1
base_url='http://www.python.com/?page={}'
print(base_url.format('1'))
#2.1
list_a = range(1, 10)
#2.2
for num in list_a:
print(num)
#2.3
for num in list_a:
req_url = base_url.format(num)
print(req_url)
#3.1
a = 'I like python'
#3.2
b = a.split(' ')
#3.3
for strs in b:
print(strs)
#3.3
for num2 in range(0,len(b)):
print(num2, b[num2])

#4.1
c = b[1]
print(c)
#4.2
d = b[2][2:4]
print(d)
#4.3
e = b[2]
nPos = e.find(d)
if nPos>=0:
print('存在')
else:
print('不存在')

#5.1
if e.startswith(d):
print('是')
else:
print('不是')

#5.2
for num in list_a:
if num<6:
print(num,'<6')
else:
print(num,'>=6')
#5.3
for num in list_a:
if num==6:
continue
print(num)
#5.4
for num in list_a:
if num>6:
break
print(num)

#6.1
dict_a = {}
print(type(dict_a))
#6.2
for num in range(0,len(list_a)):
dict_a[num] = list_a[num]
print(dict_a)
#6.3
for a in dict_a:
print(a,dict_a[a])
#6.4
encode_json = json.dumps(dict_a)
print(type(encode_json), encode_json)

#7.1
for num in range(1,10):
for snum in range(1,num+1):
res = num * snum
print(str(num)+"*"+str(snum)+"="+str(res),end=' ')
print()

相关文章

网友评论

本文标题:【Python爬虫】-第四期课后练习7

本文链接:https://www.haomeiwen.com/subject/yxwtdxtx.html