發表文章

目前顯示的是 10月, 2026的文章

吳沛穎python,方法read(),seek(0),readlines(),input

圖片
file = open('金融常識.txt','r',encoding='utf-8') lines = file.readlines() file.seek(0) reading = file.read() file.close() print(len(lines), len(reading)) x = input('金一乙吳沛穎輸入搜尋關鍵詞,列出所有題目: ') n = 0 for line in lines: if x in line: # if line.find(x) != -1: 使用python更強的功能in n += 1 # 被更常使用 print(n, ' ',line,end="")#預設結束換列 print(f'\n總共{n}題目')

吳沛穎python串列list集合set字典dict統計字元數目37,241不同字元數1,251

圖片
file = open('金融常識.txt','r',encoding='utf-8') reading = file.read() file.close() print('檔案字元characters數:', len(reading)) mySet = set(reading)#將串列轉成集合,稱她 mySet得到1251 myDict = dict() #定義字典dict稱他為 myDict例如改成DoraSet for j in mySet: myDict[j] = 0 for i in reading: myDict[i] += 1 for j in mySet: print(f"字元「{j}」出現{myDict[j]:,}次數") print(f'吳沛穎python計算字元數目{len(reading):,},不同字元數{len(mySet):,}') #python和其他所有語言不同的特徵 f string格式化字串文字 print(f"吳沛穎python計算左引號(出現次數{myDict['(']:,}") print(f'吳沛穎python計算右引號)出現次數{myDict[")"]:,}') print(f'吳沛穎python計算504每題四個選項至少有{504*4:,}') 字元「訟」出現2次數 字元「囑」出現1次數 字元「軋」出現1次數 字元「單」出現86次數 字元「就」出現23次數 字元「輸」出現2次數 字元「容」出現13次數 字元「慘」出現1次數 字元「縮」出現3次數 字元「親」出現2次數 字元「救」出現4次數 字元「斷」出現5次數 字元「室」出現3次數 字元「百」出現9次數 字元「擔」出現29次數 字元「置」出現11次數 字元「牆」出現2次數 字元「址」出現1次數 字元「)」出現2,061次數 吳沛穎python計算字元數目37,241,不同字元數1,251 吳沛穎python計算左引號(出現次數2,061 吳沛穎python計算右引號)出現次數2,061 吳沛穎python計算504每題四個選項至少...

吳沛穎w3schools學習python字串list串列set集合dict字典

A="以下有關聯合國永續發展目標(Sustainable Development Goals, SDGs)之敘述,請問何者有誤?(1)SDGs 4是「確保有教無類、公平以及高品質的教育,及提倡終身學習」(Quality Education),包含消除教育上的性別差距不能雙重標準公然性羞辱(2)SDGs 5是「實現性別平等,並賦予婦女權力」(Gender Equality),包含終結所有對婦女和女童的各種形式歧視(3)SDGs 8是「促進包容且永續的經濟成長,讓每個人都有一份好工作」(Decent Work and Economic Growth),包含保護勞工的權益,為所有勞工創造安全有保障的工作環境(4)SDGs 16是「促進和平多元的社會,確保司法平等,建立具公信力且廣納民意的體系」(Peace, Justice and Strong Institutions),包含促進及落實沒有歧視的法律與政策,以實現永續發展" a='字串string串列list集合set字典dict' B=list(A) print('利用A建構串列B',B) print('A的型態',type(A),'B的型態'type(B)) c='You are not my type.你不是我的菜。' C=set(A);print('二指令放在同一列格;',type(c)) C=set(B);print('由串列產生的集合D','type(D)) print('字串A,串列B產生的集合相等?',C==D) print('字串A,串列B產生的集合不相等?',C!=D) E = dict() 長度 411 型態 A產生串列list 字串,串列產生的集合相等?True