1. 程式人生 > >字符串方法

字符串方法

mysql runner 大寫 bce sele 替換 case 包含 變量名

# name = ‘my \t name is {name},age is {age}.‘
# print(name.capitalize())#首字母大寫
# print(name.center(100,‘S‘))#50個-,把name放中間
# print(‘歡迎看日誌‘.center(100,‘*‘))
file_name =‘a.png‘
# print(file_name.endswith(‘.png‘))#是否以x結尾
# print(file_name.find(‘fuck‘))#查找字符串的索引
# print(file_name.index(‘fuck‘))#查找字符串的索引
# print(name.format(name=‘niuniu‘,age=18))#這個是格式字符串,再第一節的博客裏面已經寫了
# print(name.format_map({‘name‘:‘niuniu‘,‘age‘:19}))#這個也是格式化字符串,後面跟的是一個字典,字典在後面也會寫
# print(‘%&(()()#¥23432sdfsd‘.isalnum())#是否包含數字和字母
# print(‘abA‘.isalpha())#是否是英文字母
# print(‘122‘.isdigit())#是否是數字
# print(‘123name‘.isidentifier())#是否是一個合法的變量名
# print(‘aaaaaAAAA‘.islower())#是否是小寫字母
# print(‘AA‘.isupper())#是否是大寫字母
# print(‘Loadrunner Book‘.istitle())#是不是一個標題,判斷首字母是否大寫
print(‘,‘.join((‘hehe‘,‘haha‘,‘ee‘)))#拼接字符串

print(‘,‘.join([‘abc‘,‘efg‘]))
# abcefg


# print(‘adbefF‘.lower())#變成小寫
# print(‘adbefF‘.upper())#變成大寫
# print(‘ mysql \n‘.lstrip())#默認去掉左邊的空格和換行
# print(‘\nmysql ‘.rstrip())#默認去掉右邊的空格和換行
# print(‘\nmysql \n‘.strip())#默認去掉兩邊邊的空格和換行
st = ‘idashixiong wangjuanxi‘
# print(st.strip(‘i‘))
# p = str.maketrans(‘abcdefg‘,‘*%^4567‘)#前面的字符串和後面的字符串做映射
# print(‘cc ae gg‘.translate(p))#輸出按照上面maketrans做映射後的字符串
# new_p = str.maketrans(‘1234567‘, ‘abcdefg‘)
# print(‘cc ae gg‘.translate(new_p))
# print(‘mysql is db.‘.replace(‘ ‘, ‘‘)) # 替換字符串
# print(‘mysql is is db‘.rfind(‘is‘)) # 返回最右邊字符的下標
print(‘1 2 3 4‘.split(‘ ‘)) # 分割字符串,返回一個list
src = ‘niuhanyang,123456‘
#niuhanyang,123456
#jmy,123456
#wjx,123456
#[‘niuhanyang,123456‘,‘jmy,123456‘,‘wjx,123456‘]
# new_src=src.split(‘\n‘)
# print(new_src[0])
# print(‘1+2+3\n1+2+3+4‘.splitlines()) # 按照換行符分割
# print(‘Abcdef‘.swapcase()) # 大小寫反轉

# src = ‘select username,password from user where name like "%{name}%";‘
# input_name = input(‘請輸入你的名字:‘)
# new_src = src.format(name=input_name)
# print(‘生成的sql語句是{sql},再來個{sql}‘.format(sql=new_src))
age = 18
money = 19.5
# zdd =input(‘輸入名字:‘)
# print(‘歡迎%s登錄‘%zdd)
# print(‘歡迎{name}登錄‘.format(name=zdd))
# print(‘歡迎‘+zdd+‘登錄‘)

# print(‘name:{name},money:{money},age:{age}‘.format(name=name,age=age,money=money))


# sql =‘insert into user values ({user_id},{username},{password},{addr},{phone});‘
# new_sql = sql.format(user_id=1,username=‘哈哈哈‘,addr=‘回龍觀‘,phone=1812312321,password=123456)
# print(new_sql)
# username = ‘niuhanyang‘
# passwd=123456
# login_sql = ‘select username,id from user where useranme={username} and password={password};‘.format(password=passwd,username=username)
# print(login_sql)

字符串方法