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

  • 相关阅读:
    串口打印信息
    网上下的ARM入门笔记
    职业生涯规划之驱动开发笔试题
    哈佛学生是如何度过大学4年的
    9G忠告打基础
    新塘M0Timer定时器篇
    ARM裸机篇按键中断
    linux驱动面试题
    裸机程序循环加法操作
    ARM裸机篇串口UART实验
  • 原文地址:https://www.cnblogs.com/fromzore/p/7868553.html
Copyright © 2011-2022 走看看