您好,登錄后才能下訂單哦!
運(yùn)算符
數(shù)據(jù)類型
int(整型)
在32位機(jī)器上,整數(shù)的位數(shù)為32位,取值范圍為-231~231-1,即-2147483648~2147483647
在64位系統(tǒng)上,整數(shù)的位數(shù)為64位,取值范圍為-263~263-1,即-9223372036854775808~9223372036854775807
- int
將字符串轉(zhuǎn)換為數(shù)字
a = "123"
print(type(a),a)
b = int(a)
print(type(b),b)
num = "0011"
v = int(num, base=16)
print(v)
- bit_lenght
# 當(dāng)前數(shù)字的二進(jìn)制,至少用n位表示
r = age.bit_length()
字符串一旦創(chuàng)建,不可修改
一旦修改或者拼接,都會造成重新生成字符串
字符串常用功能
# 1 首字母大寫
# test = "aLex"
# v = test.capitalize()
# print(v)
# 2 所有變小寫,casefold更牛逼,很多未知的對相應(yīng)變小寫
# v1 = test.casefold()
# print(v1)
# v2 = test.lower()
# print(v2)
# 3 設(shè)置寬度,并將內(nèi)容居中
# 20 代指總長度
# * 空白未知填充,一個(gè)字符,可有可無
# v = test.center(20,"中")
# print(v)
# test = "alex"
# v = test.ljust(20,"*")
# print(v)
# test = "alex"
# v = test.rjust(20,"*")
# print(v)
# test = "alex"
# v = test.zfill(20)
# print(v)
# 4 去字符串中尋找,尋找子序列的出現(xiàn)次數(shù)
# test = "aLexalexr"
# v = test.count('ex')
# print(v)
# test = "aLexalexr"
# v = test.count('ex',5,6)
# print(v)
# 5
# 以什么什么結(jié)尾
# 以什么什么開始
# test = "alex"
# v = test.endswith('ex')
# v = test.startswith('ex')
# print(v)
# 6 expandtabs,斷句20,
# test =
# v = test.expandtabs(20)
# print(v)
# 7 從開始往后找,找到第一個(gè)之后,獲取其未知
# > 或 >=
# test = "alexalex"
# 未找到 -1
# v = test.find('ex')
# print(v)
# 8 index找不到,報(bào)錯 忽略
# test = "alexalex"
# v = test.index('8')
# print(v)
# 9 格式化,將一個(gè)字符串中的占位符替換為指定的值
# test = 'i am {name}, age {a}'
# print(test)
# v = test.format(name='alex',a=19)
# print(v)
# test = 'i am {0}, age {1}'
# print(test)
# v = test.format('alex',19)
# print(v)
# 10 格式化,傳入的值 {"name": 'alex', "a": 19}
# test = 'i am {name}, age {a}'
# v1 = test.format(name='df',a=10)
# v2 = test.format_map({"name": 'alex', "a": 19})
# 11 字符串中是否只包含 字母和數(shù)字
# test = "123"
# v = test.isalnum()
# print(v)
# str
# 12 是否是字母,漢子
# test = "as2df"
# v = test.isalpha()
# print(v)
# 13 當(dāng)前輸入是否是數(shù)字
# test = "二" # 1,②
# v1 = test.isdecimal()
# v2 = test.isdigit()
# v3 = test.isnumeric()
# print(v1,v2,v3)
# 14 是否存在不可顯示的字符
# \t 制表符
# \n 換行
# test = "oiuas\tdfkj"
# v = test.isprintable()
# print(v)
# 15 判斷是否全部是空格
# test = ""
# v = test.isspace()
# print(v)
# 16 判斷是否是標(biāo)題
# test = "Return True if all cased characters in S are uppercase and there is"
# v1 = test.istitle()
# print(v1)
# v2 = test.title()
# print(v2)
# v3 = v2.istitle()
# print(v3)
# 17 ***** 將字符串中的每一個(gè)元素按照指定分隔符進(jìn)行拼接
# test = "你是風(fēng)兒我是沙"
# print(test)
# # t = ' '
# v = "_".join(test)
# print(v)
# 18 判斷是否全部是大小寫 和 轉(zhuǎn)換為大小寫
# test = "Alex"
# v1 = test.islower()
# v2 = test.lower()
# print(v1, v2)
# v1 = test.isupper()
# v2 = test.upper()
# print(v1,v2)
# 19
# 移除指定字符串
# 有限最多匹配
# test = "xa"
# # v = test.lstrip('xa')
# v = test.rstrip('9lexxexa')
# # v = test.strip('xa')
# print(v)
# test.lstrip()
# test.rstrip()
# test.strip()
# 去除左右空白
# v = test.lstrip()
# v = test.rstrip()
# v = test.strip()
# print(v)
# print(test)
# 去除\t \n
# v = test.lstrip()
# v = test.rstrip()
# v = test.strip()
# print(v)
# 20 對應(yīng)關(guān)系替換
# test = "aeiou"
# test1 = "12345"
# v = "asidufkasd;fiuadkf;adfkjalsdjf"
# m = str.maketrans("aeiou", "12345")
# new_v = v.translate(m)
# print(new_v)
# 21 分割為三部分
# test = "testasdsddfg"
# v = test.partition('s')
# print(v)
# v = test.rpartition('s')
# print(v)
# 22 分割為指定個(gè)數(shù)
# v = test.split('s',2)
# print(v)
# test.rsplit()
# 23 分割,只能根據(jù),true,false:是否保留換行
# test = "asdfadfasdf\nasdfasdf\nadfasdf"
# v = test.splitlines(False)
# print(v)
# 24 以xxx開頭,以xx結(jié)尾
# test = "backend 1.1.1.1"
# v = test.startswith('a')
# print(v)
# test.endswith('a)
# 25 大小寫轉(zhuǎn)換
# test = "aLex"
# v = test.swapcase()
# print(v)
# 26 字母,數(shù)字,下劃線 : 標(biāo)識符 def class
# a = "def"
# v = a.isidentifier()
# print(v)
# 27 將指定字符串替換為指定字符串
# test = "alexalexalex"
# v = test.replace("ex",'bbb')
# print(v)
# v = test.replace("ex",'bbb',2)
# print(v)
# 一、for循環(huán)
# for 變量名 in 字符串:
# 變量名
# break
# continue
# index = 0
# while index < len(test):
# v = test[index]
# print(v)
#
# index += 1
# print('=======')
# for zjw in test:
# print(zjw)
# test = "鄭建文妹子有種沖我來"
# for item in test:
# print(item)
# break
# for item in test:
# continue
# print(item)
# 二、索引,下標(biāo),獲取字符串中的某一個(gè)字符
# v = test[3]
# print(v)
# 三、切片
# v = test[0:-1] # 0=< <1
# print(v)
# 四、獲取長度
# Python3: len獲取當(dāng)前字符串中由幾個(gè)字符組成
# v = len(test)
# print(v)
# 五、獲取連續(xù)或不連續(xù)的數(shù)字,
# Python2中直接創(chuàng)建在內(nèi)容中
# python3中只有for循環(huán)時(shí),才一個(gè)一個(gè)創(chuàng)建
# r1 = range(10)
# r2 = range(1,10)
# r3 = range(1,10,2)
# 幫助創(chuàng)建連續(xù)的數(shù)字,通過設(shè)置步長來指定不連續(xù)
# v = range(0, 100, 5)
#
# for item in v:
# print(item)
列表格式
#########################list類中提供的方法 #######################
# li = [11, 22, 33, 22, 44]
# 參數(shù)
# 1. 原來值最后追加
# 對象.方法(..) # li對象調(diào)用append方法
# li.append(5)
# li.append("alex")
# li.append([1234,2323])
# print(li)
# 2 清空列表
# li.clear()
# print(li)
# 3 拷貝,淺拷貝
# v = li.copy()
# print(v)
# 4. 計(jì)算元素出現(xiàn)的次數(shù)
# v = li.count(22)
# print(v)
# 5. 擴(kuò)展原列表,參數(shù):可迭代對象
# li = [11, 22, 33, 22, 44]
# li.append([9898,"不得了"])
# [11, 22, 33, 22, 44, [9898, '不得了']]
# li.extend([9898,"不得了"])
# for i in [9898,"不得了"]:
# li.append(i)
# [11, 22, 33, 22, 44, 9898, '不得了']
#
# li.extend("不得了")
# print(li)
# 6. 根據(jù)值獲取當(dāng)前值索引位置(左邊優(yōu)先)
# li = [11, 22, 33, 22, 44]
# v= li.index(22)
# print(v)
# 7. 在指定索引位置插入元素
# li = [11, 22, 33, 22, 44]
# li.insert(0,99)
# print(li)
# 8、 刪除某個(gè)值(1.指定索引;2. 默認(rèn)最后一個(gè)),并獲取刪除的值
# li = [11, 22, 33, 22, 44]
# v = li.pop()
# print(li)
# print(v)
# li = [11, 22, 33, 22, 44]
# v = li.pop(1)
# print(li)
# print(v)
# 9. 刪除列表中的指定值,左邊優(yōu)先
# li = [11, 22, 33, 22, 44]
# li.remove(22)
# print(li)
# PS: pop remove del li[0] del li[7:9] clear
# 10 將當(dāng)前列表進(jìn)行翻轉(zhuǎn)
# li = [11, 22, 33, 22, 44]
# li.reverse()
# print(li)
# 11 列表的排序
# li = [11,44, 22, 33, 22]
# li.sort()
# li.sort(reverse=True)
# print(li)
####################################### 深灰魔法 #######################################
# 1.
# 索引取值
print(li[3])
# 2 切片,切片結(jié)果也是列表
print(li[3:-1])
# 3 for循環(huán)
# while循環(huán)
for item in li:
print(item)
"""
# 列表元素,可以被修改
# li = [1, 12, 9, "age", ["石振文", ["19", 10], "龐麥郎"], "alex", True]
############## 4 索引
# 修改
# li[1] = 120
# print(li)
# li[1] = [11,22,33,44]
# print(li)
# 刪除,第一種方式
# del li[1]
# print(li)
############## 5 切片
# 修改
# li[1:3] = [120,90]
# print(li)
# 刪除
# del li[2:6]
# print(li)
# 6 in 操作
# li = [1, 12, 9, "age", ["石振文", ["19", 10], "龐麥郎"], "alex", True]
# v1 = "石振文" in li
# print(v1)
# v2 = "age" in li
# print(v2)
# 7 轉(zhuǎn)換
# 字符串轉(zhuǎn)換列表 li = list("asdfasdfasdf"), 內(nèi)部使用for循環(huán)
# s = "pouaskdfauspdfiajsdkfj"
# new_li = list(s)
# print(new_li)
# 列表轉(zhuǎn)換成字符串,
# 需要自己寫for循環(huán)一個(gè)一個(gè)處理: 既有數(shù)字又有字符串
# li = [11,22,33,"123","alex"]
# # r = str(li) # '[11,22,33,"123","alex"]'
# # print(r)
# s = ""
# for i in li:
# s = s + str(i)
# print(s)
# 直接使用字符串join方法:列表中的元素只有字符串
# li = ["123","alex"]
# v = "".join(li)
# print(v)
元組,元素不可被修改,不能被增加或者刪除
tu = (11,22,33,44)
tu.count(22),獲取指定元素在元組中出現(xiàn)的次數(shù)
tu.index(22)獲取指定元素在元組的索引
# 1. 書寫格式
# tu = (111,"alex",(11,22),[(33,44)],True,33,44,)
# 一般寫元組的時(shí)候,推薦在最后加入 ,
# 元素不可被修改,不能被增加或者刪除
# 2. 索引
# v = tu[0]
# print(v)
# 3. 切片
# v = tu[0:2]
# print(v)
# 4. 可以被for循環(huán),可迭代對象
# for item in tu:
# print(item)
# 5. 轉(zhuǎn)換
# s = "asdfasdf0"
# li = ["asdf","asdfasdf"]
# tu = ("asdf","asdf")
#
# v = tuple(s)
# print(v)
# v = tuple(li)
# print(v)
# v = list(tu)
# print(v)
# v = "_".join(tu)
# print(v)
# li = ["asdf","asdfasdf"]
# li.extend((11,22,33,))
# print(li)
# 6.元組的一級元素不可修改/刪除/增加
# tu = (111,"alex",(11,22),[(33,44)],True,33,44,)
# # 元組,有序。
# # v = tu[3][0][0]
# # print(v)
# # v=tu[3]
# # print(v)
# tu[3][0] = 567
# print(tu)
# 1 根據(jù)序列,創(chuàng)建字典,并指定統(tǒng)一的值
# v = dict.fromkeys(["k1",123,"999"],123)
# print(v)
# 2 根據(jù)Key獲取值,key不存在時(shí),可以指定默認(rèn)值(None)
# v = dic['k11111']
# print(v)
# v = dic.get('k1',111111)
# print(v)
# 3 刪除并獲取值
# dic = {
# "k1": 'v1',
# "k2": 'v2'
# }
# v = dic.pop('k1',90)
# print(dic,v)
# k,v = dic.popitem()
# print(dic,k,v)
# 4 設(shè)置值,
# 已存在,不設(shè)置,獲取當(dāng)前key對應(yīng)的值
# 不存在,設(shè)置,獲取當(dāng)前key對應(yīng)的值
# dic = {
# "k1": 'v1',
# "k2": 'v2'
# }
# v = dic.setdefault('k1111','123')
# print(dic,v)
# 5 更新
# dic = {
# "k1": 'v1',
# "k2": 'v2'
# }
# dic.update({'k1': '111111','k3': 123})
# print(dic)
# dic.update(k1=123,k3=345,k5="asdf")
# print(dic)
# info = {
# "k1": 18,
# "k2": True,
# "k3": [
# 11,
# [],
# (),
# 22,
# 33,
# {
# 'kk1': 'vv1',
# 'kk2': 'vv2',
# 'kk3': (11,22),
# }
# ],
# "k4": (11,22,33,44)
# }
# print(info)
# info = {
# "k1": 18,
# 2: True,
# "k3": [
# 11,
# [],
# (),
# 22,
# 33,
# {
# 'kk1': 'vv1',
# 'kk2': 'vv2',
# 'kk3': (11,22),
# }
# ],
# "k4": (11,22,33,44)
# }
# # v = info['k1']
# # print(v)
# # v = info[2]
# # print(v)
# v = info['k3'][5]['kk3'][0]
# print(v)
# info = {
# "k1": 18,
# 2: True,
# "k3": [
# 11,
# [],
# (),
# 22,
# 33,
# {
# 'kk1': 'vv1',
# 'kk2': 'vv2',
# 'kk3': (11,22),
# }
# ],
# "k4": (11,22,33,44)
# }
# del info['k1']
#
# del info['k3'][5]['kk1']
# print(info)
# dict
# info = {
# "k1": 18,
# 2: True,
# "k3": [
# 11,
# [],
# (),
# 22,
# 33,
# {
# 'kk1': 'vv1',
# 'kk2': 'vv2',
# 'kk3': (11,22),
# }
# ],
# "k4": (11,22,33,44)
# }
# for item in info:
# print(item)
#
# for item in info.keys():
# print(item)
# for item in info.values():
# print(item)
# for item in info.keys():
# print(item,info[item])
# for k,v in info.items():
# print(k,v)
# s={1,2,3,4,5,6}
#添加
# s.add('s')
# s.add('3')
# s.add(3)
# print(s)
#清除
# s.clear()
# print(s)
#拷貝
# s1=s.copy()
s={'sb',1,2,3,4,5,6}
#隨機(jī)刪
# s.pop()
#指定刪除
# s.remove('sb')
# s.remove('hellol') #刪除元素不存在會報(bào)錯
# s.discard('sbbbb')#刪除元素不存在不會報(bào)錯
# print(s)
# python_l=['lcg','szw','zjw','lcg']
# linux_l=['lcg','szw','sb']
# p_s=set(python_l)
# l_s=set(linux_l)
# #求交集
# print(p_s,l_s)
# print(p_s.intersection(l_s))
# print(p_s&l_s)
# #求并集
# print(p_s.union(l_s))
# print(p_s|l_s)
# #差集
# print('差集',p_s-l_s)
# print(p_s.difference(l_s))
# print('差集',l_s-p_s)
# print(l_s.difference(p_s))
#交叉補(bǔ)集
# print('交叉補(bǔ)集',p_s.symmetric_difference(l_s))
# print('交叉補(bǔ)集',p_s^l_s)
python_l=['lcg','szw','zjw','lcg']
linux_l=['lcg','szw','sb']
p_s=set(python_l)
l_s=set(linux_l)
print(p_s,l_s)
# print('差集',p_s-l_s)
# p_s=p_s-l_s
p_s.difference_update(l_s)
print(p_s)
# s1={1,2}
# s2={2,3,5}
# print(s1.isdisjoint(s2)) 如果沒有交集,返回True,否則返回False"""
s1={1,2}
s2={1,2,3}
print(s1.issubset(s2))#s1 是s2 的子集
print(s2.issubset(s1))#False
print(s2.issuperset(s1))#s1 是s2 的父集
s1={1,2}
s2={1,2,3}
# s1.update(s2) #更新多個(gè)值
# s1.add(1,2,3,4) #更新一個(gè)值
# s1.union(s2) #不更新
print(s1)
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。