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))

  • 相关阅读:
    MVC学习中遇到问题
    静态类和单例模式区别
    类或方法名后加<>
    MVC5入门
    开发BI系统时的需求分析研究
    BI项目需求分析书-模板
    商业智能学习系统
    数据库设计三大范式[转]
    BW对应后台表[转]
    SQL优化方案
  • 原文地址:https://www.cnblogs.com/fromzore/p/7868553.html
Copyright © 2011-2022 走看看