(1)
addr=‘http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html‘
print(addr[-14:-5])
(2)
addr1=‘https://docs.python.org/3/library/‘
addr2=‘turtle‘
addr3=‘.html‘
print(addr1+addr2+addr3)
(3)
for i in range(1,5):
print(‘http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html‘.format(i))
(4)
addr=‘http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html‘
print(addr.rstrip(‘.html‘).split(‘_‘)[1])
(5)
words="Lately, I‘ve been, I‘ve been losing sleep Dreaming about the things that we could be But baby, I‘ve been, I‘ve been praying hard, Said, no more counting dollars We‘ll be counting stars, yeah we‘ll be counting stars I see this life like a swinging vine Swing my heart across the line And my face is flashing signs Seek it out and you shall find Old, but I‘m not that old Young, but I‘m not that bold I don‘t think the world is sold I‘m just doing what we‘re told I feel something so right Doing the wrong thing I feel something so wrong Doing the right thing I could lie, coudn‘t I, could lie Everything that kills me makes me feel alive Lately, I‘ve been, I‘ve been losing sleep Dreaming about the things that we could be But baby, I‘ve been, I‘ve been praying hard, Said, no more counting dollars "
print(words.count(‘counting‘))
(6)
words=‘this is my first my first time learning python‘
print(words.split())
(7)
list=[‘Tom‘,‘Nacy‘,‘Jackson‘,‘Kity‘]
for i in list:
print("%s:%s"%(list.index(i)+1,i))
tuple=[‘Tom‘,‘Nacy‘,‘Jackson‘,‘Kity‘]
for i in tuple:
print("%s:%s" % (tuple.index(i) + 1, i))
dict={‘Tom‘:90,‘Nacy‘:88,‘Jackson‘:60}
for key,value in dict.items():
print(‘%s:%s‘ %(key,value))
s=set([‘Tom‘,‘Nacy‘,‘Jackson‘,‘Kity‘])
for i in s:
print(i)
(8)
元祖用圆括号,列表用方括号,字典用花括号,集合花括号
元祖有序,列表有序,字典无序,集合无序
元祖不可变,列表可变,字典可变,集合可变
元祖元素任意,列表元素任意,字典元素键值对,集合元素任意