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

    字符串练习:

    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])

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

    sing="""发过要发的梦 但热烈渐觉冰冻
    跌过痛过便会懂
    谁在作弄 沉默背後也想发狂
    很想找一刹来放纵 斗胆一次如反恐
    也试过太冲动 大件事没计轻重
    错过悔过仍要冲
    冲出困局 形象似义勇军般英勇
    但结果有没有停战的沟通
    如戴著面具去掩饰倦容
    迎著炮火也依然表情轻松
    情绪不可激动 还若轻的举重
    来化解一切压力似失踪
    如放下面具去也许面红
    乘著晚风去追寻逍遥星空
    除去假的宽容 还真想不通
    曾年少的青葱 怀着理想那怕痛(忘却世间的縳束)
    谁明白像和你也许重逢
    遗憾太多却不能倒流的钟
    如琴声的哀号 连结他都哭诉
    谁明白我初衷 烦躁也是个梦 但我真的痛"""
    print(sing.count(""))

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

    article="""China is a big old country and it has a history of more than five thousand years.
    We are proud of its culture and part of the culture even influences the world greatly. For example, 
    the thought of Confucius. As Chinese economy develops very fast and plays an important role in the world,
    more and more foreigners learn mandarin in Confucius institutions. The essence of Chinese traditional culture 
    can be tested by the time. It units the whole nation and no matter what kinds of disaster comes, we will fight 
    together for the country’s future. Today, many young people lose faith in traditional culture and they are crazy 
    for the western culture. They follow the western fashion and think we are the old style.
    But some day, they will realize they are wrong to abandon traditional culture."""
    
    
    
    a1=article.replace(".",", ").replace(",",". ").replace(" . "," ").replace(""," ").replace("
    ","").split(" ")
    print(a1)
  • 相关阅读:
    HTTP协议 学习笔记一
    web发展历史
    Easydarwin加FFMPEG实现HLS流视频点播
    C# Socket异步实现消息发送--附带源码
    C# Activex调用USB摄像头--附带源码
    C# listbox DataSource数据绑定--一年半以前的bug
    ASP.NET MVC WebAPI实现文件批量上传
    ASP.NET MVC使用SignalR统计在线用户人数
    Chart.js Y轴数据以百分比展示
    Java获取字符串信息
  • 原文地址:https://www.cnblogs.com/168-hui/p/8617053.html
Copyright © 2011-2022 走看看