zoukankan      html  css  js  c++  java
  • Python基础练习

    Pycharm开发环境设置与熟悉。

    练习基本输入输出:

    print('你好,{}.'.format(name))

    print(sys.argv)

    库的使用方法:

    import ...

    from ... import ...

    条件语句:

        if (abs(pos()))<1:

            break

    循环语句:

    for i in range(5):

    while True:

    函数定义:

    def mygoto(x,y):

    def drawjx(r):



    import turtle def mygoto(x, y): turtle.up() turtle.goto(x, y) turtle.down(); def drawwjx(x): turtle.begin_fill() for i in range(5): turtle.forward(x) turtle.right(144) turtle.end_fill() turtle.setup(600, 400, 0, 0) turtle.color("yellow") turtle.bgcolor("red") turtle.fillcolor("yellow") mygoto(-250, 75) drawwjx(100) for i in range(4): x = 1 if i in [0, 3]: x = 0 mygoto(-100 + x * 50, 150 - i * 40) turtle.left(15 - i * 15) drawwjx(30) mygoto(0, 0) turtle.hideturtle() turtle.done()
    http://news.gzcc.cn/html/2017/xiaoyuanxinwe 
    n_1027/8443.html
    
    取得校园新闻的编号
    
    str1='http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html'
    print(str1[-9:-5])
    结果:
    
    
    
    https://docs.python.org/3/library/turtle.ht 
    ml
    
    产生python文档的网址
    
    str2='https://docs.python.org/3/library/turtle.html'
    print(str2.replace("turtle","python"))
    结果:
    
    
    
    http://news.gzcc.cn/html/xiaoyuanxinwen/4.h 
    tml
    
    产生校园新闻的一系列新闻页网址
    
    add3='http://news.gzcc.cn/html/xiaoyuanxinwen/'
    add4='.html'
    for i  in range(4):
        result=add3+str(i)+add4
        print(result)
    
    
    练习字符串内建函数: 
    strip,lstrip,rstrip,split,count
    
    用函数得到校园新闻编号
    
    str5='http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html'
    print(str5.split('_',2)[1].rstrip('.html'))
    

      

    用函数统计一歌词中单词出现的次数
    >>> song = '''
    There For You - Martin Garrix/Troye Sivan
    Written by:Bea Miller/Brady Riley/Brett McLaughlin/Martin Garrix/Troye Sivan
    I woke up pissed off today
    And lately everyone feels fake
    Somewhere I lost a piece of me
    Smoking cigarettes on balconies
    But I can't do this alone
    Sometimes I just need a light
    If I call you on the phone
    Need you on the other side
    So when your tears roll down your pillow like a river
    I'll be there for you
    I'll be there for you
    When you're screaming but they only hear you whisper
    I'll be loud for you
    But you gotta be there for me too
    But you gotta be there for me too
    Last year took a toll on me
    But I made it with you next to me
    Around the world and back again
    I hope you're waiting at the end
    But I can't do this alone
    Sometimes I just need a light
    If I call you on the phone
    Need you on the other side
    So when your tears roll down your pillow like a river
    I'll be there for you
    I'll be there for you
    When you're screaming but they only hear you whisper
    I'll be loud for you
    I'll be loud for you
    I got you I promise
    Let me be honest
    Love is a road that goes both ways
    When your tears roll down your pillow like a river
    I'll be there for you
    But you gotta be there for me too
    But you gotta be there for me too
    Boy I'm holding on to something
    Won't let go of you for nothing
    I'm running running just to keep my hands on you
    There was a time that I was so blue
    What I got to do to show you
    I'm running running just to keep my hands on you
    Running running just to keep my hands on you
    Running running just to keep my hands on you
    So I'm running running just to keep my hands on you
    But you gotta be there for me too
    But you gotta be there for me too
    '''
    >>> song.count('you')
    38

    
    

      

  • 相关阅读:
    Cesium 模拟卫星扫描
    SQL Server配置管理器”远程过程调用失败“的问题解决
    Windows系统查看端口占用、结束进程方法和命令
    Cesium 遥感卫星影像推送效果绘制
    Nginx 发布本地后台端口
    js 产生16位随机字符串
    vscode powershell/gitbash g++ : 无法将“g++”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。 所在位置 行:1 字符: 1
    安装Tomcat服务器以及错误汇总(tomcat8.0、jdk8)
    Windows 8及以上系统安装好SQL Server 2008之后找不到SQL Server配置管理器的问题
    mysql 利用binlog增量备份,还原实例
  • 原文地址:https://www.cnblogs.com/zhongchengzhe/p/8609758.html
Copyright © 2011-2022 走看看