zoukankan      html  css  js  c++  java
  • 字符串练习

    1.字符串练习:

    http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html

    取得校园新闻的编号

    acc="http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html"
    print(acc[-14:-5])

    https://docs.python.org/3/library/turtle.html

    产生python文档的网址

    abb1="http://doc.python.org/3/library/"
    abb2=".html"
    abb3="turtle"
    print(abb1+abb3+abb2)

    http://news.gzcc.cn/html/xiaoyuanxinwen/4.html

    产生校园新闻的一系列新闻页网址

    add1="http://news.gzcc.cn/html/xiaoyuanxinwen"
    add2=".html"
    for i in range(2,10):
        add=add1 + str(i) + add2
        print(add)

    练习字符串内建函数:strip,lstrip,rstrip,split,count

    用函数得到校园新闻编号

    a="http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html"
    print(a.rstrip(".html").split("_")[1])

    用函数统计一歌词中单词出现的次数

    song='''

    sunday's coming i wanna drive my car
    to your apartment with present like a star
    forecaster said the weather may be rainy hard
    but i know the sun will shine for us
    oh lazy seagull fly me from the dark
    i dress my jeans and feed my monkey banana
    then i think my age how old,skyline how far
    or we need each other in california
    you show me your body before night comes down
    i touch your face and promise to stay ever young
    on this ivory beach we kissed so long
    it seems that the passion's never gone
    you sing me your melody and i feel so please
    i want you to want me to keep your dream
    together we'll run wild by a summer symphony
    this is what we enjoyed not a fantasy
    the tin-man's surfing i wanna try my luck
    to the top of tide rip like just have some drugs
    i know you have no blame for my proud moonish heart
    welcom to the golden beatnik park
    oh diamond seashore drag me from the yard
    incredible sunward i watch as you're in photograph
    for camera your smile's so sweet,palm trees' so lush
    would you believe my honey it's califonia
    you show me your body before night comes down
    i touch your face and promise to stay ever young
    on this ivory beach we kissed so long
    it seems that the passion's never gone
    you sing me your melody and i feel so please
    i want you to want me to keep your dream
    together we'll run wild by a summer symphony
    this is what we enjoyed not a fantasy

    '''
    print('the在歌曲里一共出现了'+ str(song.count('the')) +'')

    将字符串分解成一个个的单词。

    s='it seems that the passion's never gone'
    
    s.split()
  • 相关阅读:
    安卓ADB学习笔记
    css样式和定义的class都没问题,但样式却没生效
    Linux文件系统
    bat批处理下如何像shell一样将命令执行的效果赋值给变量
    windows下svn post-commit的实现
    windows下安装subversion
    nginx sendfile 相关知识
    centos6.9下 svn 1.7.10版本 编译安装
    Django问题 Did you rename .....a ForeignKey
    Django:cookie和session相关问题
  • 原文地址:https://www.cnblogs.com/lk666/p/8617999.html
Copyright © 2011-2022 走看看