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

  • 相关阅读:
    给右键 添加dos命令
    js模拟系统无刷新跳回登录页1
    MBProgressHUD.h file not found
    建立个人博客网站
    <转>提高iOS开发效率的方法和工具
    设置模块功能设计思路及代码实现
    经验之谈
    'NSInteger' (aka 'long') to 'int32
    OCR技术
    升级Xcode6.4插件失效解决办法
  • 原文地址:https://www.cnblogs.com/fromzore/p/7868553.html
Copyright © 2011-2022 走看看