zoukankan      html  css  js  c++  java
  • Python--字符串基本操作

    #!/usr/bin/env python
    # -*- coding:utf-8 -*-
    # Author:Huanglinsheng
    
    # name.capitalize()  首字母大写
    # name.casefold()   大写全部变小写
    # name.center(50,"-")  输出 '---------------------Alex Li----------------------'
    # name.count('lex') 统计 lex出现次数
    # name.encode()  将字符串编码成bytes格式
    # name.endswith("Li")  判断字符串是否以 Li结尾"Alex	Li".expandtabs(10) 输出'Alex      Li', 将	转换成多长的空格
    # name.find('A')  查找A,找到返回其索引, 找不到返回-1
    
    '''format'''
    '''
    msg = "my name is {},my age is {}"
    msg.format("hls",22)
    print(msg.format("hls",22))
    
    msg = "my name is {1},my age is {0}"
    msg.format("hls",22)
    print(msg.format("hls",22))
    
    msg = "my name is {name},my age is {age}"
    msg.format(name="hls",age=22)
    print(msg.format(name="hls",age=22))
    
    
    msg = "my name is {},my age is {}"
    msg.format_map({'name':'alex','age':22})
    '''
    
    # msg.index('a')  返回a所在字符串的索引
    # '9aA'.isalnum()   True
    #
    # '9'.isdigit() 是否整数
    # name.isnumeric
    # name.isprintable
    # name.isspace
    # name.istitle
    # name.isupper
    #  "|".join(['alex','jack','rain'])
    # 'alex|jack|rain'
    
    
    #字符替换
    intab = "aeiou"
    outtab = "12345"
    trantab = str.maketrans(intab,outtab)
    str = "this is string example....wow!!!"
    str.translate(trantab)
    print(str.translate(trantab))
    
    
    #msg.swapcase 大小写互换
  • 相关阅读:
    WCF自定义消息编码器 part 2 from MSDN
    EYQiPa,梦开始的地方
    WCF负载平衡 from MSDN
    WCF安全体系结构 from MSDN
    Introduction to Locking in SQL Server z
    WCF 性能计数器 from MSDN
    关于EYQiPa 持续更新
    12 个免费在线的 Web 网站性能测试工具 转
    使用FileSystemWatcher监控目录 z
    IIS相关
  • 原文地址:https://www.cnblogs.com/huanglinsheng/p/9361253.html
Copyright © 2011-2022 走看看