• 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,'####,再倒序')
  • 相关阅读:
    excel套模板
    随便写写
    Ajax请求本页
    解除默认asp.net 上传文件大小的限制
    客户端获取mac ip 主机名
    获取客户端Mac
    vue中使用swiper出现Can't resolve 'swiper/dist/css/swiper.css'
    win10 输入法小技巧
    VS Code 编辑器配置备份
    axios报错: Cannot read property 'protocol' of undefined ....
  • 原文地址:https://www.cnblogs.com/nfyx/p/8783361.html
Copyright © 2020-2023  润新知