美文网首页Python五期爬虫作业
【Python爬虫作业】- 字符串分割、索引和切片

【Python爬虫作业】- 字符串分割、索引和切片

作者: 丽雁解 | 来源:发表于2017-12-26 17:37 被阅读1次
    str1 = 'http://www.jianshu.com/u/bd3cfc499940'
    key='/u/'
    
    print('step 2:',str1[22+len(key):])
    
    s = "abcdefg"
    print('step 3:\ns=',s)
    print('s[3]:',s[3])
    print('s[2:4]:',s[2:4])
    print('s[:5]:',s[:5])
    print('s[3:]:',s[3:])
    print('s[::-1]:',s[::-1])
    print('s[::2]:',s[::2])
    
    list1 = [1,2,3,4,5,6,7]
    print('step 4:\nlist1=',list1)
    print('list1[3]:',list1[3])
    print('list1[:5]:',list1[:5])
    print('list1[3:]:',list1[3:])
    print('list1[::-1]:',list1[::-1])
    print('list1[::2]:',list1[::2])
    

    运行结果

    step 2: bd3cfc499940
    step 3:
    s= abcdefg
    s[3]: d
    s[2:4]: cd
    s[:5]: abcde
    s[3:]: defg
    s[::-1]: gfedcba
    s[::2]: aceg
    step 4:
    list1= [1, 2, 3, 4, 5, 6, 7]
    list1[3]: 4
    list1[:5]: [1, 2, 3, 4, 5]
    list1[3:]: [4, 5, 6, 7]
    list1[::-1]: [7, 6, 5, 4, 3, 2, 1]
    list1[::2]: [1, 3, 5, 7]
    

    相关文章

      网友评论

        本文标题:【Python爬虫作业】- 字符串分割、索引和切片

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