• 015_string


    #!/usr/bin/env python
    # Author:liujun

    name = "my name is aliex"

    print(name.capitalize())
    # Capitalize the first letter

    print(name.count('a'))
    # Count the number of specified character

    print(name.center(50, "-"))
    # The result is ----------------------aliex-----------------------

    print(name.endswith("x"))
    # Decide whether the string end with specified character and return boolean

    print(name.find("name"))
    print(name.find("y"))
    # Get the index of the first character of the given string

    name = "my name is {name} and i am {year} old"
    print(name.format(name="alex",year=33))

    print(name.isalnum())
    print(name.isalpha())
    print(name.isdigit())
    # Decide if it is a digit
    print(name.isdecimal())
    # Decide if it is decimal
    print(name.isidentifier())
    # Decide if it is a valid identifier.

    print(name.islower())
    print(name.isupper())
    print(name.isnumeric())
    print(name.istitle())
    print(name.isprintable())

    print('+'.join( ['1','2','3']) )

    print( name.ljust(50,'*') )
    print( name.rjust(50,'-') )

    print( 'Alex'.lower() )
    print( 'Alex'.upper() )


    print( ' Alex'.lstrip() )
    print( 'Alex '.rstrip() )
    print( ' Alex '.strip() )


    p = str.maketrans("abcdefli",'123$@456')
    print("alex li".translate(p) )

    print('alex li'.replace('l','L',1))

    print('alex lil'.rfind('l'))

    print('1+2+3+4'.split(' '))
    print('1+2 +3+4'.splitlines())

    print('Alex Li'.swapcase())
    print('lex li'.title())
    print('lex li'.zfill(50))






  • 相关阅读:
    使用NoSQL Manager for MongoDBclient连接mongodb
    Shell编程(二)条件控制,流程控制及循环控制
    Shell编程(一)参数引用,特殊字符及常用的操作符
    日常使用的linux总结记录--不断更新中
    oracle数据库中的连表查询
    前端css样式2
    前端css样式
    前端基础知识
    mysql执行计划, 事务处理
    sql 索引优化
  • 原文地址:https://www.cnblogs.com/liujun5319/p/9588521.html
Copyright © 2020-2023  润新知