zoukankan      html  css  js  c++  java
  • python for 格式化字符串 list.count

    1.格式化字符串--------------------------------------
    name = input("your name:")
    age = input("your age:")
    if age.isdigit():
    age = int(age)
    else:
    # print("plz input a num")
    exit("plz input a num")
    job= input("your job:")

    info ='''
    -------------the info of %s -----------
    the name is %s
    the age is %d
    the job is %s
    -------------------
    ''' % (name,name,age,job) #这里的百分号和里面的值,对应上面的占位符 %s表字符串 %d 表数字 %f 表浮点数

    print(info)



    2---------------for----------------
    # for i in range(1,100,2):# 1,表示起始 100,表示最终,2 表示步长。 (不写默认为1步)。
    # print(i)

    _name = "ming"
    _password = "abc"

    for i in range(1,4):
    name = input("input you name:")
    password = input("input you password:")
    if _name == name and _password == password:
    print("well come %s to our club" % name )
    break
    else:
    print("there is no more than %s times" % (3-i) )
    if i == 3:
    exit(" you have on chance")
    3--------------break-----------------------
    break_flag = False
    for i in range(10):
    print(i)
    if i==9:
    for j in range(10):
    print("lak2",j)
    if j==5:
    break_flag=True
    break
    if break_flag==True:
    break
    4-------------list count-------------------------
    
    
    a=['br','td','td','tr','br'].count('br') #统计tr出现的个数
    b=['br','td','td','tr','br']
    c=['3',3]
    c.extend(b) #把C扩展b里的内容
    print(a)
    print(b)
    print(c)

    #index 查找内容所在的位置
    d=c.index('td') # 即查td所在的位置
    print(d)

    #reverse 倒序
    print(c,'@@@@@@@正序')
    k = c.reverse() #这个没有返回值,
    print(k,'#---c.reverse() 这个没有返回值 -----倒序#')
    print(c,'--------倒序')
    #当然还可以这样子
    e = c[::-1] #这个就有返回值了
    print(e,'####,再倒序')
  • 相关阅读:
    lambda表达式
    Shiro身份认证---转
    反转数组
    HashMap去重
    开发工具软件下载地址
    setInterval的使用和停用
    手机端的META
    spring自定义参数绑定(日期格式转换)
    mybatis注解动态sql
    SpringMVC文件上传
  • 原文地址:https://www.cnblogs.com/nfyx/p/8783361.html
Copyright © 2011-2022 走看看