zoukankan      html  css  js  c++  java
  • string函数的使用

    name="my name is fromzore i am 19 {years} old"
    print(name.capitalize())#这个函数是使name的首字母变为大写
    print(name.count("a"))#这个函数是看列表里的某个元素在str里出现的次数
    print(name.center(50,"-"))#center是输出name的时候让她居中,第一个参数是输出的字符串长度,第二个是不够的位子用什么补充
    print(name.endswith("ex"))#endswith是检测str是否以你输入的参数为结尾,如果是输入true,不是输出false
    print(name.expandtabs(tabsize=30))#expandtabs是将str中的 转化为空格,里面的参数是一个tab是多少个空格

    import time
    import redis

    client=redis.StrictRedis()

    def is_action_allowed(user_id,action_key,period,max_count):
        key='hist:%s%s'%(user_id,action_key)
        now_ts=int(time.time()*1000)
        with client.pipeline() as pipe:
            pipe.zadd(key,now_ts,now_ts)
            pipe.zremrangebyscore(key,0,now_ts-period*1000)
            pipe.zcard(key)
            pipe.expire(key,period)
            _,_,current_count,_=pipe.execute()
        return current_count<=max_count


    for i in range(20):
        print(is_action_allowed('hello','reply',60,5))

  • 相关阅读:
    Shell脚本sed命令
    Shell脚本常用unix命令
    Shell的case语句
    3.5.2 数值之间的转换
    3.5.1 数学函数与常量
    3.5 运算符
    3.4.2 常量
    3.4.1 变量初始化
    3.4 变量
    Python异常捕捉的一个小问题
  • 原文地址:https://www.cnblogs.com/fromzore/p/7868553.html
Copyright © 2011-2022 走看看