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()
  • 相关阅读:
    Http方法:Get请求与Post请求的区别
    udev和rules使用规则
    c++中的动态内存分配
    c++中重载运算符
    c++中静态成员函数
    c++中值传递,址传递,引用传递
    c++中实现单例模式singleton class
    [Windows篇] 在windows 10上源码编译gtest 并编写CMakeLists.txt
    [Ubuntu篇] 在ubuntu上源码编译gtest,编写gtest-config.cmake并测试
    使用boost data_time模块来获取毫秒级时间并转换为string字符串
  • 原文地址:https://www.cnblogs.com/lk666/p/8617999.html
Copyright © 2011-2022 走看看