zoukankan      html  css  js  c++  java
  • 疑问题

     使用while循环实现输出2-3+4-5+6...+100 的和

    for 循环

    2、查找列表中元素,移除每个元素的空格,并查找以a或A开头并且以c结尾的所有元素。
    li=["alec","aric","Alex","Tony","rain"]
    tu=("alec","aric","Alex","Tony","rain")
    dic={'k1':"alex",'k2':'aric',"k3":"Alex","k4":"Tony"}

     1 li = ["alec", "aric", "Alex", "Tony", "rain"]
     2 tu = ("alec", "aric", "Alex", "Tony", "rain")
     3 dic = {'k1': "alex", 'k2': 'aric', "k3": "Alex", "k4": "Tony"}
     4 
     5 list1 = list(tu)
     6 list2 = list(dic.values())
     7 newlist = li + list1 + list2
     8 for i in newlist:
     9 ret = i.strip() #i.strip():删除字符串当前行首尾的的空格
    10 if (ret.startswith('a') or ret.startswith('A')) and ret.endswith('c'): #startswith查看是否已什么开始,endswith查看是否已什么结尾
    11 print(ret)
    View Code

    其中,startswith和endswith这两个语法在哪里学习的?

  • 相关阅读:
    5.1、字符串插入
    2.2、部署 Discuz!
    7.1.5、测试数组
    4.2、php 注释
    5.2、操作符
    2.3、初始化 Discuz!
    5.3、控制结构
    gradle 又一项目构建工具
    1.1、概述
    7.1.8、通过追加数组的方式创建数组
  • 原文地址:https://www.cnblogs.com/aaaajayheng1990/p/8644136.html
Copyright © 2011-2022 走看看