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( '\nAlex'.lstrip() )
print( 'Alex\n'.rstrip() )
print( ' Alex\n'.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('\n'))
print('1+2\n+3+4'.splitlines())

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






posted on 2018-09-04 21:13  langjitianyadaolao  阅读(71)  评论(0编辑  收藏  举报

导航