資料型別 字串

2022-06-25 01:18:08 字數 939 閱讀 6989

一字串

定義:它是乙個有序的字元的集合,用於儲存和表示基本的文字資訊

『』 或""中間包含的內容稱之為字串

特性

1只能存放乙個值

2不可變

3按照從左到右的順序定義字元集合,下表從0開始順序訪問,有序

字串的常用操作

移除空白  .strip()

首字母大寫.capitalize()  所有大寫 .upper()

統計字元長度 count()

以什麼作為結尾 .endswith()

以什麼作為開頭.startswith

查詢.find()

格式化字串.rormat()

檢視字元的索引=.index()

替換=.replace('alex','sb')#把alex替換成sb

分割=.split()

長度=.len()

索引====舉例 x=『hello world』

print(x[2])

切片

print(x[1:3])

Python資料型別 字串型別

變數名 str 變數值 msg hello world print msg 0 print msg 1 msg hello n print len msg msg hello world print ello in msg print lo w not in msg res print hello ...

資料型別 字串型別 string

1 字串 數字,都會轉為字串來儲存 2 以二進位制的方式儲存在記憶體中 必須掌握的命令 1.設定乙個key value set key value 2.獲取key的值 get key 3.key不存在時再進行設定 nx set key value nx 4.設定過期時間 ex 過了日期就自動銷毀ex...

Schema 字串資料型別

字串資料型別用於可包含字串的值。字串資料型別可包含字元 換行 回車以及製表符。下面是乙個關於某個 scheme 中字串宣告的例子 文件中的元素看上去應該類似這樣 john smith或者類似這樣 john smith注釋 如果您使用字串資料型別,xml 處理器就不會更改其中的值。規格化字串資料型別源...