2019-05-23
一、#資料型別的內建函式
python有哪些資料型別?
number 數值型
string 字元型
list 列表
tuple 元組
dict 字典
set 集合
二、## 字串的簡單操作
+ 字串的連線操作
* 字串的複製操作
字串的索引操作
[: :] 字串的切片操作
[開始索引: 結束索引: 間隔值] (包含開始, 不包含結尾)
str1 = 'lo'
str2 = 've'
print(str1 + str2)
print('lo' + 've')
print('#'*10)
s = 'i like dog'
print(s[-1])
s = '012345678'
# 指定範圍切字串
print(s[2:5])
# 指定範圍並且給出間隔值
print(s[2:6])
print(s[2:6:2])
# 切整個字串
print(s[:])
#指定開始,不指定結束
print(s[2:])
# 指定結束,不指定開始
print(s[:4])
# 指定開始,不指定結束,並給出間隔值
print(s[2::3])
#指定結束,不指定開始並給出間隔值
print(s[:6:2])
三、help(str)
四、# capitalize() 首字母大寫 返回的是字串
s = 'i like dog'
print(s.capitalize())
五、# capitalize() 首字母大寫 返回的是字串
s = 'i like dog'
print(id(s))
new_s = s.capitalize()
print(id(new_s))
六、# title() 將每個單詞的首字母變為大寫 返回的是字串
s = 'i like dog'
print(s.title())
七、# upper() 將所有字母變為大寫字母 返回的是字串
s = 'i 狗 like dog'
print(s.upper())
八、# swapcase() 大小寫互換 返回的是字串
s = 'i 狗 like dog'
print(s.swapcase())
八、# len()計算字串長度,不屬於字串的內建函式
s = 'i 狗 like dog'
s1 = 'i like dog'
print(len(s))
print(len(s1))
九、# find() 查詢指定字串,找不到返回-1 找到返回索引值
# index() 查詢指定字串,找不到報錯
s = 'asdfghjklasdfghjkl'
s1 = s.find('a',2,10)
s2 = s.index('a')
print(s1)
print(s2)
十、# count() 計算字串出現次數
s = 'asdfghjklasdfghjkl'
print(s.count('g'))
十一、# startswith() 檢測是否已指定字母開頭
# endswith() 檢測是否 以指定字母結束
s = 'i like dog'
print(s.startswith('i'))
print(s.startswith('i'))
print(s.endswith('g'))
print(s.endswith('g'))
--------------------------------------
十二、# isupper() 檢測所有字母是否是大寫字母 返回的都是布林值
s = 'fgh'
s1 = 'dfgh'
print(s.isupper())
print(s1.isupper())
print('='*20)
# islower() 檢測所有字母是否是小寫字母
print(s.islower())
print(s1.islower())
print('='*20)
#istitle() 檢測是否以指定標題顯示(每個單詞首字母大寫)
print(s.istitle())
print(s1.istitle())
s2 = 'i like dog'
print(s2.istitle())
print('='*20)
# isspace() 檢測字串是否是空字串
s = ' '
s1 = 'i like '
s2 = ''
print(s.isspace())
print(s1.isspace())
print(s2.isspace())
print('='*20)
------------------------------
十三、# isalpha() 檢測字串是否是字母組成 返回布林值
s = 'i 狗 like dog'
print(s.isalpha())
-----------------------------
十四、# isalpha() 檢測字串是否是字母組成 返回布林值
s = 'i 狗 like dog'
s1 = 'i狗likedog'
print(s.isalpha())
print(s1.isalpha())
----------------------------
十五、
Python 內建資料型別
1 字串 string 1 str this is string print str print type str 2 str 想怎麼些就怎麼些 怎麼的 print str print type str 注意 單引號 雙引號均可,使用三個引號,其內容可以自由書寫 2 布林型別 bool bool f...
python內建資料型別 數字
型別 子型別示例 相關模組 數字整數 2 100 2的100次方 import math import random 浮點數複數等 小數物件 表現固定精度的特性 例如 頭寸的合計 以及實現更好的數字精度是乙個理想的工具 0.1 0.1 0.1 0.3 5.551115123125783e 17 fr...
Python 內建資料型別(二)
一 字串 不可改變物件 1 定義 有序的字元的集合,用單引號或者雙引號表示,支援索引,切片 就是編號,通過這個編號就能找到相應的儲存空間。正數從左到右,負數從右到左。切片 sx sx 3 sx 2 sx 0 4 2 是指對操作物件擷取其中的一部分 語法 起始 結束 步長 注意 選取的區間屬於左閉右開...