CD2021 40823139

  • Home
    • Site Map
    • reveal
    • blog
  • Stage-1
    • 最終結果
    • 問題檢討
      • 最佳化設計
      • 模擬的碰撞問題
      • 機構模型過於理想
      • 時間裕度
    • week2
    • week3
    • week4
  • Stage-2
    • week6
    • week7
    • week8
    • week9
  • Stage-3
    • 模型簡化
    • W16 exam
    • W13~W14
      • 翻譯
      • Pick and Place
    • task1
      • 獲得正確順序(沒嵌入網站)
      • 嵌入網站
    • task2
    • task3
  • 機器人學
    • 正向運動學
    • 逆向運動學
  • Program
    • 基礎Python
      • package-example
      • geometry
      • funtion-args
      • funtion-basic
      • loop-basic
      • loop-control
      • module
      • number-string
      • set-dictionary
      • start
      • datatype
      • condition
      • list-tuple
  • About
  • 學期總結
  • CMSiMDE
    • 基本操作
      • 編輯網頁內容
      • 上傳與引用檔案
      • 上傳與引用圖片
      • 嵌入程式碼
      • 嵌入影片檔
      • 檢視 STL
    • Gitlab 同步
    • Heroku 部署
    • Fossil SCM
  • 建立網頁
  • 網站錯誤
    • 標題選擇
    • 靜態網頁 404
    • 動態網站錯誤
    • 出現ValueError
  • 延伸開發
number-string << Previous Next >> start

set-dictionary

s = {3,4,5,6}
print(3 in s)
#印出3這個資料,是否在s裡面

s = {3,4,5,6}
print(3 not in s)
#印出3這個資料,是否"不是"在s裡面

s1 = {1,2,3}
s2 = {2,3,4}
s3 = s1&s2 
print(s3)
#印出s1與s2的交集s3

s3 = s1|s2 
print(s3)
#取得s1與s2的聯集,但不會重複取資料(因為聯集的概念)

s3 = s1-s2 
print(s3)
#從s1減掉與s2相同的部分,即差集(注意!s1-s2不等於s2-s1)

s3 = s1^s2 
print(s3)
#反交集,取s1與s2中不重疊部分

s = set("loveyou")
print(s)
#把set(字串)拆成集合,不過順序不會照原本的(因為集和本來就沒順序)
print("s" in s)
#印出s這個資料是否在s集合中

#字典運算
dic={"love":'愛',"you":'你'}
print(dic["love"])
#印出字典裡love代表什麼

dic["love"] = "like"
print(dic["love"])
#把字典裡love原本的定義更改成like

dic={"love":'愛',"you":'你'}
print("love" in dic)
#判斷love是否在字典裡

dic={"love":'愛',"you":'你'}
print("愛" in dic)
#判斷"love"是否在字典裡,實際上字典裡只有love 與 you ,剩下:的東西是定義

del dic["love"]
print(dic)
#刪除字典中的love

dic={x:x*2 for x in{3,4,5}}
print(dic)
#用列表產生字典,而字典定義看函數決定


number-string << Previous Next >> start

Copyright © All rights reserved | This template is made with by Colorlib