1、使用{}的方法
2、%的方法s1 = 'hello {}! my name is {}.'.format('world', 'python貓')
print(s1)
s2 = 'hello my name is .'.format('world','python 貓')
print(s2)
s3 = 'hello ! my name is .'.format(name1='world',name2='python 貓')
print(s3)
print('%s %s' % ('hello', 'world'))
3、使用()類似元組的方法
4、物件導向模板拼接s_tuple = ('hello',' ','world')
s_like_tuple = ('hello' ' ' 'world')
print(s_tuple)
print(s_like_tuple)
type(s_like_tuple)
5、+號方式from string import template
s = template('$ $!')
print(s.safe_substitute(s1='hello',s2='world'))
6、join()拼接方式str_1 = 'hello world! '
str_2 = 'my name is python貓.'
print(str_1 + str_2)
print(str_1)
7、f-stringstr_list = ['hello','wordl']
str_join1 = ''.join(str_list)
str_join2 = '-'.join(str_list)
print(str_join1)
print(str_join2)
去除字串空格 / 或回車、換行符name = 'world'
myname = 'python_cat'
words = f' hello . my name is .'
去除字串開頭或結尾空格 .strip(), lstrip(), rstrip()
去除全部空格:
法一:字串替換 replace(old, new, count)
法二:join為字元字串合成傳入乙個字串列表,
split為字串分割可以按規則進行分割,分割後為列表
字母大小寫轉換
字串判斷所有字元轉大寫 .upper()
所有字元轉小寫 .lower()
第乙個字母轉大寫 .capitalize()
每個單詞的首字母轉大寫 .title()
字串查詢判斷字串是否只包含字母或數字 .isalnum()
判斷字串是否只包含字母 .isalpha()
判斷字串是否只包含數字 .isdigit()
判斷字串是否全部為大寫 .isupper()
判斷字串是否全部為小寫 .islower()
判斷字串是否都是首字母大寫 .title()
判斷字串是否全部為空白字元、\t、\r、\n .isspace()
判斷字串是否包含字串 使用成員操作符 in
查詢指定範圍內字串a中是否包含str find(str, beg=0, end=len(string))
#返回值為str的下標,若str不存在,則報錯(valueerror)
字串的增刪改查
ios 開發中一些字串的處理 增 nsmutablestring str nsmutablestring alloc init str insertstring atindex 4 str insertstring atindex 7 nslog str 2016 12 12 1,新建乙個 nsmu...
C string字串的增刪改查
本文出自 徐xiho的部落格 c 提供的string類包含了若干實用的成員函式,大大方便了字串的增加 刪除 更改 查詢等操作。插入字串 insert 函式可以在string字串中置頂的位置插入另乙個字串,它的原型為 string insert size t pos,const string str ...
資料操作 增刪改查
select from 表名 例 查詢所有學生資料 select from students新增一行資料 格式一 所有字段設定值,值的順序與表中字段的順序對應 insert into 表名 values 例 插入乙個學生,設定所有欄位的資訊 insert into students values 0...