string函数的使用

name="my \tname 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中的\t转化为空格,里面的参数是一个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))

posted @ 2018-12-25 14:57  fromzore  阅读(125)  评论(0编辑  收藏  举报