zoukankan      html  css  js  c++  java
  • python每日一题001

    学习python之后,经常因为平时用不到,然后就生疏了。就像背英文单词时,一直在背,但是一直停留在第一页。吸取了教训以后,决定参考成功者的方法,每天写一道编程题,一来巩固自己的知识,二来不至于把学过的东西忘掉。

    现在开始记录所做的题目。

    给定一个字符串,每个字符后面添加一个空格,返回一个新的字符串。

    例如:

    I am a student

    返回结果应为

    I  a m  a  s t u d e n t 

    实现代码如下:

    方法1:

    str = "I am a student"

    newstr  = " ".join(str)

    print(newstr)

    打印结果

    方法二:

    def newstr(str):
      newstring = ""
      for i in str:
        if i != " ":
          newstring += ( i + " ")
        else:
          newstring += i
      return newstring
    if __name__ == "__main__":
      string = "I am a student"
      print(newstr(string))

    打印结果:

  • 相关阅读:
    linux ioctl
    pkg-config用法和gcc cflags
    boost noncopyable类
    google protobuf使用2
    跨平台编译CMake使用
    Linux epoll
    docker安装
    python 脚本转成exe可执行程序
    shell相关知识
    tcpdump使用
  • 原文地址:https://www.cnblogs.com/littlebird1/p/8524820.html
Copyright © 2011-2022 走看看