• python3基础之“小练习(3)”


    (二十四)将字符串"A screaming comes across the sky."中所有的"s"字符替换为美元符号。
    1 # a="A screaming comes across the sky."
    2 # a=a.replace("s","$")
    3 # print(a)
    (二十五)找到字符串"Hemingway"中字符"m"所在的第一个索引。
    1 # a="Hemingway"
    2 # print(a.index("m"))
    (二十六)在你最喜欢的书中找一段对话,将其变成一个字符串。
    1 # a="岁月不待人"
    2 # print(a)
    (二十七)先后使用字符串拼接和字符串乘法,创建字符串"three three three"。
    1 # a="thr"
    2 # b="ee"
    3 # c=a+b
    4 # print(c)
    5 # v=c*3
    6 # print(v)  输出“threethreethree”
    #补充:
    # v=c+" "
    # print(v*3)  输出“three three three ”
     
    (二十八)对字符串"It was bright cold day in April, and the clocks were striking thirteen."进行切片,只保留逗号之前的字符。
    1 # a="It was bright cold day in April,and the clorcks were strking thirteen."
    2 # a=a.split(",")
    3 # # print(a)
    4 # print(a[0:1])
    (二十九)打印以下列表["The Walking Dead", "Entourage", "The Sopranos","The Vampire Diaries"]中的每个元素。
    1 # q=["The Walking Dead", "Entourage", "The Sopranos","The Vampire Diaries"]
    2 # for i in q:
    3 #     print(i)
    (三十)打印从25 到50 之间的所有数字。
    1 # for i in range(25,50):
    2 #     print(i)
    (三十一)打印第一个挑战练习中的每个元素及其索引。
    1 # a=["The Walking Dead", "Entourage", "The Sopranos","The Vampire Diaries"]
    2 # for i in a :
    3 #     print(i)
    4 #     s=a.index(i)
    5 #     print(s)
    (三十二)编写一个包含死循环和数字列表的程序(可选择输入q 退出)。每次循环时,请用户猜一个在列表中的数字,然后告知其猜测是否正确。
    1 # a=input("type a str:")
    2 # while a=="b":
    3 #     if a=="q":
    4 #         break
    5 #         end
    6 #     print("right!")
    (三十三)将列表[8, 19, 148, 4]中的所有数字,与列表[9, 1, 33, 83]中的所有数字相乘,并将结果添加到第3 个列表中。
    1 # a=[8,19,148,4]
    2 # s=[9,1,33,83]
    3 # d=[]
    4 # for i in a:
    5 #     for j in s:
    6 #         d.append(i*j)
    7 # print(d)

    如有不足,欢迎指正!

  • 相关阅读:
    Linux中常用操作命令
    JQuery Each循环遍历每个元素
    get set
    Launch Screen在iOS7/8中的实现
    程序猿必备的Git教程
    浏览器的工作原理:新式网络浏览器幕后揭秘
    浏览器的工作原理:新式网络浏览器幕后揭秘
    游览器中javascript的执行过程
    游览器中javascript的执行过程
    浅析 Cordova for iOS
  • 原文地址:https://www.cnblogs.com/wangwenchao/p/11329656.html
Copyright © 2020-2023  润新知