s40723210 cad2019

  • Home
    • Site Map
    • reveal
    • blog
  • Weeks
    • Week2-5
    • Week6-9
    • Week10-14
      • Solidworks-history
      • NX-history
      • Inventor-history
      • Creo(ProE)-history
    • Week15-18
    • 期末報告
  • Notes
    • git基本指令
    • python基本語法
      • 練習-1
      • 練習-2
      • 練習-3
      • 練習-4
    • vi 與 vim 的指令整理
    • Dos 基本指令
    • SolveSpace的快捷鍵
    • Nx12快捷鍵
    • Video device
    • Q&A
  • Organize books
    • Space Modeling with SolidWorks and NX
    • NX 12 for Engineering Design
      • 第一章-簡介
      • 第二章-入門教學
      • 第三章-二維草圖
      • 第四章-三維建模
      • 第五章-基本草圖
      • 第六章-組配建模
      • 第七章-曲面建模
      • 第八章-有限元素分析
      • 第九章-程式編寫與模擬
  • CAD software
    • AutoCAD
    • Inventor
    • Solidworks
    • solvespace
    • NX
    • Onshape
    • Creo(ProE)
  • About
練習-1 << Previous Next >> 練習-3

練習-2

# 集合的運用

1
2
3
4
s1={3,4,5}
print(3 in s1)
print(10 in s1)
print(10 not in s1)

True
False
True

1
2
3
4
5
6
7
8
9
10
s1={3,4,5}
s2={4,5,6,7}
s3=s1&s2 # 交集︰取兩個集合中,相同的資料
print(s3)
s3=s1|s2 # 聯集︰取兩個合中的所有資料,但不重複取
print(s3)
s3=s1-s2 # 差集︰從 s1 中,減去和 s2 重疊的部分
print(s3)
s3=s1^s2 # 反交集︰取兩個集合中,重複的部分
print(s3)

{4, 5}
{3, 4, 5, 6, 7}
{3}
{3, 6, 7}

1
2
3
4
s=set("Hello") # 把字串中的字母折拆成集合︰ set(字串)
print(s)
print("H" in s)
print("A" in s)

{'H', 'e', 'l', 'o'}
True
False

#字典的運用︰key-value 配對

1
2
3
4
5
dic={"apple":"蘋果","bug":"蟲蟲"}
print(dic)
print(dic["apple"])
dic["apple"]="小蘋果"
print(dic["apple"])

{'apple': '蘋果', 'bug': '蟲蟲'}
蘋果
小蘋果

1
2
3
4
5
6
dic={"apple":"蘋果","bug":"蟲蟲"}
print("apple" in dic) # 判斷 key 是否存在
print("test" in dic)
print("test" not in dic)
del dic["apple"] # del(刪除)字典中的鍵值對 (key-value pair)
print(dic)

True
False
True
{'bug': '蟲蟲'}

1
2
dic={x:x*2 for x in [3,4,5]} # 從列表[3,4,5]的資料中產生字典
print(dic)

{3: 6, 4: 8, 5: 10}


練習-1 << Previous Next >> 練習-3

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