From a5906864e0a791c09ad793a0be0de66bc5598180 Mon Sep 17 00:00:00 2001 From: Cheung4843 <46809977+cheung4843@users.noreply.github.com> Date: Tue, 6 Feb 2024 23:20:13 +0800 Subject: [PATCH] Deployed 4efe54d with MkDocs version: 1.5.3 --- 404.html | 237 +++ about/index.html | 237 +++ blog/2024/02/06/hello-blog-/index.html | 1270 ++++++++++++++++ blog/archive/2024/index.html | 1306 ++++++++++++++++ blog/category/blog/index.html | 1324 +++++++++++++++++ blog/index.html | 1271 ++++++++++++++++ fundamental/cpp/create_env/index.html | 237 +++ fundamental/cpp/hello_world/index.html | 237 +++ fundamental/cpp/index.html | 237 +++ fundamental/index.html | 237 +++ fundamental/python/index.html | 237 +++ fundamental/python/lists/index.html | 277 +++- fundamental/python/operators/index.html | 257 +++- .../python/repetition_structures/index.html | 270 +++- fundamental/python/say_hello/index.html | 237 +++ .../python/selection_structures/index.html | 265 +++- fundamental/python/sets/index.html | 752 ++++++++++ fundamental/python/tuples/index.html | 237 +++ .../python/variable_and_input/index.html | 237 +++ index.html | 237 +++ license/index.html | 255 ++++ search/search_index.json | 2 +- sitemap.xml | 52 +- sitemap.xml.gz | Bin 344 -> 386 bytes 24 files changed, 9832 insertions(+), 76 deletions(-) create mode 100755 blog/2024/02/06/hello-blog-/index.html create mode 100755 blog/archive/2024/index.html create mode 100755 blog/category/blog/index.html create mode 100755 blog/index.html diff --git a/404.html b/404.html index 8b24fe1..c8df0a5 100755 --- a/404.html +++ b/404.html @@ -288,6 +288,26 @@ + + + + + + +
  • + + + + + + Blog + + +
  • + + + + @@ -817,6 +837,223 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + + + +
  • + + + diff --git a/about/index.html b/about/index.html index 529cc09..877d7ca 100755 --- a/about/index.html +++ b/about/index.html @@ -296,6 +296,26 @@ + + + + + + +
  • + + + + + + Blog + + +
  • + + + + @@ -833,6 +853,223 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + + + +
  • + + + diff --git a/blog/2024/02/06/hello-blog-/index.html b/blog/2024/02/06/hello-blog-/index.html new file mode 100755 index 0000000..d8d5bb7 --- /dev/null +++ b/blog/2024/02/06/hello-blog-/index.html @@ -0,0 +1,1270 @@ + + + + + + + + + + + + + + + + + + + + + Hello Blog ! - LMcps Book + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + 跳轉到 + + +
    +
    + +
    + + + + +
    + + +
    + +
    + + + + + + + + + +
    +
    + + + + + + + + + + + +
    +
    +
    + + + +
    +
    +
    + + + +
    +
    +
    +
    + + +
    +
    +
    +
    + + + + + + + +

    Hello Blog !

    +

    Hi, this is a test post.

    +

    For the better experience of the development, I think recording the process of the development is a good idea.

    + + +

    If you are interested in the project, you can follow the blog to get the latest information about the project.

    +

    Also, plaease contact me if you wanna join the project. I am looking forward to working with you.

    + + + + + + + + + + + + + + + + + + +
    +
    + + + +
    + + + +
    + + + +
    +
    +
    +
    + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/blog/archive/2024/index.html b/blog/archive/2024/index.html new file mode 100755 index 0000000..95812c3 --- /dev/null +++ b/blog/archive/2024/index.html @@ -0,0 +1,1306 @@ + + + + + + + + + + + + + + + + + + + + + + + 2024 - LMcps Book + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + 跳轉到 + + +
    +
    + +
    + + + + +
    + + +
    + +
    + + + + + + + + + +
    +
    + + + +
    +
    +
    + + + + + + + +
    +
    +
    + + + +
    +
    +
    + + + +
    +
    +
    + + + +
    +
    +
    +

    2024

    +
    + +
    +
    + + + + +
    +
    +

    Hello Blog !

    +

    Hi, this is a test post.

    +

    For the better experience of the development, I think recording the process of the development is a good idea.

    + + +
    +
    + + + + + + + + + + +
    +
    + + + +
    + + + +
    + + + +
    +
    +
    +
    + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/blog/category/blog/index.html b/blog/category/blog/index.html new file mode 100755 index 0000000..6e654ed --- /dev/null +++ b/blog/category/blog/index.html @@ -0,0 +1,1324 @@ + + + + + + + + + + + + + + + + + + + + + + + + + Blog - LMcps Book + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + 跳轉到 + + +
    +
    + +
    + + + + +
    + + +
    + +
    + + + + + + + + + +
    +
    + + + +
    +
    +
    + + + + + + + +
    +
    +
    + + + +
    +
    +
    + + + +
    +
    +
    + + + +
    +
    +
    +

    Blog

    +
    + +
    +
    + + + + +
    +
    +

    Hello Blog !

    +

    Hi, this is a test post.

    +

    For the better experience of the development, I think recording the process of the development is a good idea.

    + + +
    +
    + + + + + + + + + + +
    +
    + + + +
    + + + +
    + + + +
    +
    +
    +
    + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/blog/index.html b/blog/index.html new file mode 100755 index 0000000..1aa8ebe --- /dev/null +++ b/blog/index.html @@ -0,0 +1,1271 @@ + + + + + + + + + + + + + + + + + + + + + + + + + Blog - LMcps Book + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + 跳轉到 + + +
    +
    + +
    + + + + +
    + + +
    + +
    + + + + + + + + + +
    +
    + + + +
    +
    +
    + + + + + + + +
    +
    +
    + + + +
    +
    +
    + + + +
    +
    +
    + + + +
    +
    +
    +

    Blog

    +
    + +
    +
    + + + + +
    +
    +

    Hello Blog !

    +

    Hi, this is a test post.

    +

    For the better experience of the development, I think recording the process of the development is a good idea.

    + + +
    +
    + + + + + + + + + + +
    +
    + + + +
    + + + +
    + + + +
    +
    +
    +
    + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/fundamental/cpp/create_env/index.html b/fundamental/cpp/create_env/index.html index bd77026..f66ad90 100755 --- a/fundamental/cpp/create_env/index.html +++ b/fundamental/cpp/create_env/index.html @@ -301,6 +301,26 @@ + + + + + + +
  • + + + + + + Blog + + +
  • + + + + @@ -991,6 +1011,223 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + + + +
  • + + + diff --git a/fundamental/cpp/hello_world/index.html b/fundamental/cpp/hello_world/index.html index d2d5a9e..b56209e 100755 --- a/fundamental/cpp/hello_world/index.html +++ b/fundamental/cpp/hello_world/index.html @@ -301,6 +301,26 @@ + + + + + + +
  • + + + + + + Blog + + +
  • + + + + @@ -976,6 +996,223 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + + + +
  • + + + diff --git a/fundamental/cpp/index.html b/fundamental/cpp/index.html index b8697f2..d221ce6 100755 --- a/fundamental/cpp/index.html +++ b/fundamental/cpp/index.html @@ -301,6 +301,26 @@ + + + + + + +
  • + + + + + + Blog + + +
  • + + + + @@ -834,6 +854,223 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + + + +
  • + + + diff --git a/fundamental/index.html b/fundamental/index.html index 68cc698..d2af6e6 100755 --- a/fundamental/index.html +++ b/fundamental/index.html @@ -301,6 +301,26 @@ + + + + + + +
  • + + + + + + Blog + + +
  • + + + + @@ -832,6 +852,223 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + + + +
  • + + + diff --git a/fundamental/python/index.html b/fundamental/python/index.html index 19054d7..590ccb4 100755 --- a/fundamental/python/index.html +++ b/fundamental/python/index.html @@ -301,6 +301,26 @@ + + + + + + +
  • + + + + + + Blog + + +
  • + + + + @@ -834,6 +854,223 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + + + +
  • + + + diff --git a/fundamental/python/lists/index.html b/fundamental/python/lists/index.html index bc00cda..e26b3f7 100755 --- a/fundamental/python/lists/index.html +++ b/fundamental/python/lists/index.html @@ -301,6 +301,26 @@ + + + + + + +
  • + + + + + + Blog + + +
  • + + + + @@ -1081,6 +1101,223 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + + + +
  • + + + @@ -1836,7 +2073,7 @@

    JaggedPractice

    -

    Itsa - [C_MM33-易] 找1~N的完美數

    +

    Itsa - [C_MM33-易] 找1~N的完美數

    Reference code @@ -1880,7 +2117,7 @@

    Practice -

    Itsa - [C_MM44-易] The Numbers

    +

    Itsa - [C_MM44-易] The Numbers

    Reference code @@ -1903,7 +2140,7 @@

    Practice -

    Itsa - [C_AR01-易] 一維陣列反轉 I

    +

    Itsa - [C_AR01-易] 一維陣列反轉 I

    Reference code @@ -1920,7 +2157,7 @@

    Practice -

    Itsa - [C_AR03-易] 計算陣列中所有元素的立方和

    +

    Itsa - [C_AR03-易] 計算陣列中所有元素的立方和

    Reference code @@ -1945,7 +2182,7 @@

    Practice -

    Itsa - [C_AR09-易] 兩數差值

    +

    Itsa - [C_AR09-易] 兩數差值

    Reference code @@ -1977,7 +2214,7 @@

    Practice\(10\),再加上下一個數字。

    Reference code @@ -2004,7 +2241,7 @@

    Practice -

    Itsa - [C_AR025-易] 計算ASCII字元

    +

    Itsa - [C_AR025-易] 計算ASCII字元

    Reference code @@ -2033,7 +2270,7 @@

    Practice -

    Itsa - [C_AR029-難] 文字編碼

    +

    Itsa - [C_AR029-難] 文字編碼

    Reference code @@ -2077,40 +2314,40 @@

    PracticeAssignment

    @EditTime : 2024-02-03 21:30

    diff --git a/fundamental/python/operators/index.html b/fundamental/python/operators/index.html index 1029afc..bb481d9 100755 --- a/fundamental/python/operators/index.html +++ b/fundamental/python/operators/index.html @@ -301,6 +301,26 @@ + + + + + + +
  • + + + + + + Blog + + +
  • + + + + @@ -964,6 +984,223 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + + + +
  • + + + @@ -1451,7 +1688,7 @@

    Bonus: map for inputPractice

    有了本章的基礎後,其實已經可以做很多題目了,我們來做一些練習題吧!

    Reference code @@ -1463,7 +1700,7 @@

    Practice -

    Itsa - [C_MM02-易] 計算三角形面積

    +

    Itsa - [C_MM02-易] 計算三角形面積

    Reference code @@ -1475,7 +1712,7 @@

    Practice -

    Itsa - [C_MM04-易] 計算總和、乘積、差、商和餘數

    +

    Itsa - [C_MM04-易] 計算總和、乘積、差、商和餘數

    Reference code @@ -1493,7 +1730,7 @@

    Practice -

    Itsa - [C_MM06-易] 英哩轉公里

    +

    Itsa - [C_MM06-易] 英哩轉公里

    Reference code @@ -1506,22 +1743,22 @@

    PracticeAssignment

    @EditTime : 2024-01-28 22:03

    diff --git a/fundamental/python/repetition_structures/index.html b/fundamental/python/repetition_structures/index.html index 04a2fac..5ea5c8f 100755 --- a/fundamental/python/repetition_structures/index.html +++ b/fundamental/python/repetition_structures/index.html @@ -301,6 +301,26 @@ + + + + + + +
  • + + + + + + Blog + + +
  • + + + + @@ -961,6 +981,223 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + + + +
  • + + + @@ -1432,7 +1669,7 @@

    Bonus: for ... else and while ... else

    Practice

    Reference code @@ -1445,7 +1682,7 @@

    Practice -

    Itsa - [C_MM26-易] 輸出 1x1、2x2、...、NxN之結果

    +

    Itsa - [C_MM26-易] 輸出 1x1、2x2、...、NxN之結果

    Reference code @@ -1459,7 +1696,7 @@

    Practice -

    Itsa - [C_MM33-易] 找1~N的完美數

    +

    Itsa - [C_MM33-易] 找1~N的完美數

    Reference code @@ -1493,7 +1730,7 @@

    Practice -

    Itsa - [C_MM34-易] 因數問題

    +

    Itsa - [C_MM34-易] 因數問題

    Reference code @@ -1515,37 +1752,40 @@

    PracticeAssignment

    +

    @EditTime : 2024-01-30 21:51

    diff --git a/fundamental/python/say_hello/index.html b/fundamental/python/say_hello/index.html index 7897470..226e388 100755 --- a/fundamental/python/say_hello/index.html +++ b/fundamental/python/say_hello/index.html @@ -301,6 +301,26 @@ + + + + + + +
  • + + + + + + Blog + + +
  • + + + + @@ -883,6 +903,223 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + + + +
  • + + + diff --git a/fundamental/python/selection_structures/index.html b/fundamental/python/selection_structures/index.html index a183c3f..8197ca4 100755 --- a/fundamental/python/selection_structures/index.html +++ b/fundamental/python/selection_structures/index.html @@ -301,6 +301,26 @@ + + + + + + +
  • + + + + + + Blog + + +
  • + + + + @@ -934,6 +954,223 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + + + +
  • + + + @@ -1355,7 +1592,7 @@

    match ... case@EditTime : 2024-01-29 12:32

    Practice

    Reference code @@ -1371,7 +1608,7 @@

    Practice -

    Itsa - [C_MM13-易] 停車費計算

    +

    Itsa - [C_MM13-易] 停車費計算

    Reference code @@ -1405,7 +1642,7 @@

    Practice -

    Itsa - [C_MM15-易] 判斷座標是否在正方形的範圍內

    +

    Itsa - [C_MM15-易] 判斷座標是否在正方形的範圍內

    Reference code @@ -1424,37 +1661,37 @@

    PracticeAssignment

    @EditTime : 2024-01-29 14:38

    diff --git a/fundamental/python/sets/index.html b/fundamental/python/sets/index.html index e1ec458..0250506 100755 --- a/fundamental/python/sets/index.html +++ b/fundamental/python/sets/index.html @@ -301,6 +301,26 @@ + + + + + + +
  • + + + + + + Blog + + +
  • + + + + @@ -707,6 +727,117 @@ + + +
  • + + + Create a Set + + + +
  • + +
  • + + + Operations + + + + + +
  • + +
  • + + + Methods + + + + + +
  • + +
  • + + + Practice + + + +
  • + +
  • + + + Assignment + + +
  • @@ -883,6 +1014,223 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + + + +
  • + + + @@ -916,6 +1264,117 @@ + + +
  • + + + Create a Set + + + +
  • + +
  • + + + Operations + + + + + +
  • + +
  • + + + Methods + + + + + +
  • + +
  • + + + Practice + + + +
  • + +
  • + + + Assignment + + +
  • @@ -938,6 +1397,299 @@

    Sets

    Introduction

    +

    如果給你一個串列,請你檢查裡面有沒有重複的元素,你會怎麼做呢?你會怎麼樣確保裡面的元素是唯一的呢?

    +

    在這一章,我們將會學習到集合(Set),它有以下特性:

    +
      +
    • 無序: 集合裡面的元素是沒有順序的
    • +
    • 不重複: 集合裡面的元素是唯一的
    • +
    • 可變: 可以新增、刪除元素,但是裡面的元素必須是不可變的(immutable)
    • +
    • 用大括號{}來表示,裡面的元素用逗號,隔開
    • +
    +

    Create a Set

    +

    你可以用set()來建立一個集合,或者用大括號{},直接看例子:

    +
     1
    + 2
    + 3
    + 4
    + 5
    + 6
    + 7
    + 8
    + 9
    +10
    +11
    +12
    +13
    a = set("FOREVER")
    +print(a)
    +
    +b = [4, 8, 4, 3]
    +c = set(b)
    +print(c)
    +
    +d = {(0, 1), (1, 2), (2, 3)}
    +print(d)
    +print(type(d))
    +
    +e = {}
    +print(type(e))
    +
    +
    Output
    1
    +2
    +3
    +4
    +5
    {'R', 'F', 'O', 'E', 'V'}
    +{8, 3, 4}
    +{(2, 3), (1, 2), (0, 1)}
    +<class 'set'>
    +<class 'dict'>
    +
    +

    SUHO(수호) _ FOREVER

    +

    你得注意,建立空集合的時候,你必須用set(),因為{}是用來建立空字典的。

    +

    以及所謂的無序,你試著多執行幾次程式,你會發現,每次輸出的結果都不一樣。

    +

    你甚至可以用 Comprehension 來建立集合。

    +
    1
    +2
    +3
    +4
    +5
    +6
    +7
    a = {1, 2, 3}
    +b = {3, 4, 5}
    +diff_b = {x for x in b if x not in a}
    +print(diff_b)
    +
    +c = {x ** 2 for x in range(-3, 4)}
    +print(c)
    +
    +
    Output
    1
    +2
    {4, 5}
    +{0, 9, 4, 1}
    +
    +

    Operations

    +

    Accessing elements

    +

    因為集合是無序的,所以你不能用索引來存取元素,但是你可以用in來檢查元素是否存在,以及搭配for迴圈來遍歷集合。

    +
    1
    +2
    +3
    +4
    +5
    perfect_nums_set = {6, 28, 496, 8128, 33550336}
    +print(4843 in perfect_nums_set)
    +
    +for num in perfect_nums_set:
    +    print(num, end=' ')
    +
    +
    Output
    1
    +2
    False
    +33550336 8128 496 6 28 
    +
    +
    +

    Question

    +

    對於一個長度為 \(n\) 的集合,你認為需要花幾個步驟檢查某一個元素是否存在?

    +
    +

    答案可能會讓你驚訝,不需要 \(n\) 個步驟,只要幾個步驟就好,可以說是馬上。

    +

    Union

    +

    你可以用| 或者 union() 來取得兩個集合的聯集。

    +
    1
    +2
    +3
    +4
    +5
    +6
    +7
    +8
    +9
    a = {1, 3, 5}
    +b = {2, 4, 5, 6}
    +
    +print(a.union(b))
    +c = a | b
    +print(c)
    +
    +a |= b
    +print(a)
    +
    +
    Output
    1
    +2
    +3
    {1, 2, 3, 4, 5, 6}
    +{1, 2, 3, 4, 5, 6}
    +{1, 2, 3, 4, 5, 6}
    +
    +

    Intersection

    +

    你可以用& 或者 intersection() 來取得兩個集合的交集。

    +
    1
    +2
    +3
    +4
    +5
    +6
    +7
    +8
    +9
    a = {1, 3, 5}
    +b = {2, 4, 5, 6}
    +
    +print(a.intersection(b))
    +c = a & b
    +print(c)
    +
    +a &= b
    +print(a)
    +
    +
    Output
    1
    +2
    +3
    {5}
    +{5}
    +{5}
    +
    +

    Difference

    +

    你可以用- 或者 difference() 來取得兩個集合的差集。

    +
    1
    +2
    +3
    +4
    +5
    +6
    +7
    +8
    +9
    a = {1, 3, 5}
    +b = {2, 4, 5, 6}
    +
    +print(a.difference(b))
    +c = b - a
    +print(c)
    +
    +a -= b
    +print(a)
    +
    +
    Output
    1
    +2
    +3
    {1, 3}
    +{2, 4, 6}
    +{1, 3}
    +
    +

    我就舉這三個例子,其他請你自己查 Docs 來學習。

    +

    Methods

    +

    Adding elements

    +

    你可以用 add() 來新增元素到集合中。

    +
    1
    +2
    +3
    +4
    nums_set = {1, 2, 3, 4, 5}
    +nums_set.add(6)
    +nums_set.add(3)
    +print(nums_set)
    +
    +
    Output
    {1, 2, 3, 4, 5, 6}
    +
    +

    也可以用 update() 來新增多個元素到集合中。

    +

    其實就跟 |= 一樣。

    +
    1
    +2
    +3
    +4
    +5
    +6
    nums_set = {1, 2, 3, 4, 5}
    +nums_set.update({6, 7})
    +print(nums_set)
    +
    +nums_set.update([1, 8, 9], {10, 11})
    +print(nums_set)
    +
    +
    Output
    1
    +2
    {1, 2, 3, 4, 5, 6, 7}
    +{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
    +
    +

    Removing elements

    +

    你可以用 remove() 來移除集合中的元素,如果元素不存在,會拋出錯誤。

    +
    1
    +2
    +3
    +4
    +5
    a = {1, 2, 3}
    +a.remove(1)
    +print(a)
    +a.remove(1)
    +print(a)
    +
    +
    Output
    1
    +2
    {2, 3}
    +KeyError: 1
    +
    +

    或者用 discard() 來移除集合中的元素,如果元素不存在,不會拋出錯誤。

    +
    1
    +2
    +3
    +4
    +5
    a = {1, 2, 3}
    +a.discard(2)
    +print(a)
    +a.discard(2)
    +print(a)
    +
    +
    Output
    1
    +2
    {1, 3}
    +{1, 3}
    +
    +

    那怎麼清空呢?你可以用 clear() 來清空集合。

    +
    1
    +2
    +3
    a = {1, 2, 3}
    +a.clear()
    +print(len(a))
    +
    +
    Output
    0
    +
    +

    還有更多的方法,請你自己查 Docs 來學習,但這些目前應該夠你用。

    +

    Practice

    + +
    +Reference code +

    1
    +2
    +3
    +4
    +5
    +6
    +7
    n = int(input())
    +num_set = set(input().split())
    +
    +if len(num_set) == n:
    +    print(1)
    +else:
    +    print(0)
    +
    +檢查有沒有重複的元素,這個問題就很適合用集合來解決,因為集合裡面的元素是唯一的,所以只要檢查集合的長度是否等於輸入串列的長度就好。

    +
    +

    Assignment

    +

    在 Itsa 上不太好找題目,所以乾脆附上解答。

    + +
    +Reference code +

     1
    + 2
    + 3
    + 4
    + 5
    + 6
    + 7
    + 8
    + 9
    +10
    a, b = input().split(',')
    +a_set = set(str.lower(a))
    +a_set.discard(" ")
    +b_set = set(str.lower(b))
    +b_set.discard(" ")
    +
    +if a_set == b_set:
    +    print(1)
    +else:
    +    print(0)
    +
    +這裡應該能感受 discard() 的用處,題目要求不區分大小寫,所以我們先把字串轉成小寫,然後再把空白字元移除(不管有沒有),最後再檢查兩個集合是否相等。

    +
    +

    @EditTime : 2024-02-06 23:16

    diff --git a/fundamental/python/tuples/index.html b/fundamental/python/tuples/index.html index ad3d169..6c3c8b8 100755 --- a/fundamental/python/tuples/index.html +++ b/fundamental/python/tuples/index.html @@ -301,6 +301,26 @@ + + + + + + +
  • + + + + + + Blog + + +
  • + + + + @@ -1003,6 +1023,223 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + + + +
  • + + + diff --git a/fundamental/python/variable_and_input/index.html b/fundamental/python/variable_and_input/index.html index fd57be7..7cf1db6 100755 --- a/fundamental/python/variable_and_input/index.html +++ b/fundamental/python/variable_and_input/index.html @@ -301,6 +301,26 @@ + + + + + + +
  • + + + + + + Blog + + +
  • + + + + @@ -916,6 +936,223 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + + + +
  • + + + diff --git a/index.html b/index.html index 6ddbea8..5a99c36 100755 --- a/index.html +++ b/index.html @@ -299,6 +299,26 @@ + + + + + + +
  • + + + + + + Blog + + +
  • + + + + @@ -913,6 +933,223 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + + + +
  • + + + diff --git a/license/index.html b/license/index.html index 3df3d1f..71e9bd3 100755 --- a/license/index.html +++ b/license/index.html @@ -14,6 +14,8 @@ + + @@ -294,6 +296,26 @@ + + + + + + +
  • + + + + + + Blog + + +
  • + + + + @@ -831,6 +853,223 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + + + +
  • + + + @@ -935,6 +1174,22 @@

    License

    + + + + + + diff --git a/search/search_index.json b/search/search_index.json index 2ff354a..a958917 100755 --- a/search/search_index.json +++ b/search/search_index.json @@ -1 +1 @@ -{"config":{"lang":["en"],"separator":"[\\s\\u200b\\u3000\\-\u3001\u3002\uff0c\uff0e\uff1f\uff01\uff1b]+","pipeline":["stemmer"]},"docs":[{"location":"","title":"Hello LMcps Book!","text":""},{"location":"#welcome_to_lmcps","title":"Welcome to LMcps!","text":"

    \u9ece\u660e\u8cc7\u8a0a\u793e(LMcps)\u5275\u7acb\u65bc2018\u5e74\uff0c\u6307\u5c0e\u8005\u70ba\u674e\u60e0\u6587\u8001\u5e2b\u3002

    \u672c\u66f8\u7684\u6b63\u78ba\u6253\u958b\u65b9\u5f0f\u662f\u6697\u8272\u6a21\u5f0f\u3002

    print(\"Hello LMcps Book!\")\nprint(\"Welcome to LMcps!\")\n
    "},{"location":"#why_does_it_start","title":"Why does it start?","text":"

    \u57282024/1/25\uff0c\u662f\u75ab\u60c5\u5f8c\uff0c\u7b2c\u4e00\u6b21\u6b77\u5c46\u793e\u54e1\u8fd4\u56de\u6bcd\u6821\u8207\u5b78\u5f1f\u59b9\u5011\u5206\u4eab\u7d93\u9a57\u7684\u65e5\u5b50\uff0c\u5728\u8207\u8001\u5e2b\u53ca\u5b78\u5f1f\u59b9\u5011\u4ea4\u6d41\u5f8c\uff0c\u767c\u73fe\u4e86\u76ee\u524d\u8cc7\u8a0a\u6559\u80b2\u7684\u7a98\u56f0\uff0c\u8af8\u5982\u7db2\u8def\u4e0a\u7684\u8cc7\u6e90\u96d6\u591a\uff0c\u4f46\u4e0d\u6613\u5165\u9580\uff0c\u65bc\u662f\u6c7a\u5b9a\u5beb\u4e00\u672c\u66f8\uff0c\u4ee5\u5927\u91cf\u7684\u5716\u7247\u53ca\u7c21\u55ae\u7684\u6587\u5b57\uff0c\u8b93\u5b78\u5f1f\u59b9\u5011\u80fd\u5920\u5feb\u901f\u5165\u9580\uff0c\u4e26\u4e14\u80fd\u5920\u5728\u77ed\u6642\u9593\u5167\uff0c\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\u8207\u81ea\u4fe1\u3002

    "},{"location":"#content","title":"Content","text":"

    \u9019\u672c\u66f8\u8457\u91cd\u65bc\u61c9\u7528\u9762\uff0c\u4e26\u4e14\u5be6\u4f5c\u70ba\u4e3b\uff0c\u4e5f\u4e26\u975e\u5e36\u4f60\u6253\u7af6\u7a0b\uff0c\u800c\u662f\u5e36\u4f60\u4e86\u89e3\u91cd\u8981\u7684\u8cc7\u6599\u7d50\u69cb\u8207\u6f14\u7b97\u6cd5\u3002\u5be6\u4f5c\u8a9e\u8a00\u4ee5Python\u70ba\u4e3b\uff0c\u6703\u6709\u5c11\u6578C++\u7684\u5be6\u4f5c\u3002

    "},{"location":"#wait_to_be_done","title":"Wait to be done","text":"
    1. \u5fc3\u5f97\u5206\u4eab\u5c08\u5340
    2. \u5c08\u696d\u7528\u8a9e
    "},{"location":"#contributors","title":"Contributors","text":""},{"location":"license/","title":"License","text":"

    MIT License

    Copyright (c) 2023 Cheung4843

    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

    "},{"location":"fundamental/","title":"Fundamental","text":"

    \u9019\u88e1\u5c07\u6703\u6559\u4f60\u57fa\u790e\u7684Python\u8207C++\u7684\u57fa\u790e\u8a9e\u6cd5\u3002

    "},{"location":"fundamental/cpp/","title":"C++","text":"

    \u6211\u662fc++\u7cfb\u5217\u7684\u7b46\u8005bloodnighttw\uff0c\u6211\u9810\u8a08\u5728\u6b64\u6587\u7ae0\u5206\u4e0b\u5217\u5e7e\u500b\u7ae0\u7bc0\uff0c\u4e26\u76e1\u91cf\u4ee5\u521d\u5b78\u8005\u7684\u89d2\u5ea6\u5beb\u51fa\u5167\u5bb9\u3002

    1. \u74b0\u5883\u67b6\u8a2d
    2. Hello world (\u57fa\u672c\u8f38\u51fa\u5165)
    3. \u578b\u614b\u3001\u8b8a\u6578\u8207\u76f8\u95dc\u904b\u7b97
    4. \u6d41\u7a0b\u63a7\u5236
    5. \u8ff4\u5708
    6. \u51fd\u5f0f
    7. struct & class
    8. \u6307\u6a19\u8207\u53c3\u7167
    9. standard template libary

    \u5982\u679c\u5728\u64b0\u5beb\u4e0a\u6709\u4efb\u4f55\u554f\u984c\uff0c\u4f60\u53ef\u4ee5\u5bc4\u96fb\u5b50\u90f5\u4ef6\u5230 bbeenn1227@gmail.com \u6216\u8005 emails@bntw.dev \u4f86\u505a\u8a62\u554f(\u4e0d\u904e\u8acb\u8868\u660e\u4f60\u7684\u8eab\u4efd\uff0c\u4e0d\u7136\u6211\u53ef\u80fd\u6703\u5ffd\u7565)\uff0c\u6216\u8005\u53ef\u4ee5\u5728\u6211\u66f4\u5e38\u51fa\u73fe\u7684discord\u8a62\u554f\u6211\u3002

    \u6b64\u9023\u7d50\u70ba\u9ece\u660e\u8cc7\u8a0a\u793e\u7684discord\u7fa4\u7d44\u9023\u7d50\uff0c\u52a0\u5165\u4e4b\u5f8c\u53ef\u4ee5tag @bloodnighttw\uff0c\u53ea\u8981\u6211\u5728\u7dda\u4e0a\u4e14\u6709\u6642\u9593\u6211\u90fd\u6703\u76e1\u91cf\u5e6b\u4f60\u56de\u7b54\u3002

    \u53e6\u5916\u6709\u4efb\u4f55\u932f\u5b57\u6216\u53ef\u4ee5\u6539\u5584\u7684\u5730\u65b9\u8acb\u767cissues\uff0c\u6211\u5011\u6703\u518d\u8a0e\u8ad6\u904e\u5f8c\u9069\u6642\u5730\u505a\u51fa\u4fee\u6b63\u3002

    "},{"location":"fundamental/cpp/create_env/","title":"0. \u74b0\u5883\u67b6\u8a2d","text":"

    \u6b63\u6240\u8b02\u5de5\u6b32\u5584\u5176\u4e8b\uff0c\u5fc5\u5148\u5229\u5176\u5668\uff0c\u6b64\u7ae0\u6211\u5011\u5206\u5225\u6703\u5728\u5206\u5225\u8b1b\u8ff0\u5982\u4f55\u5728windows\u3001macos\u4e0a\u5b89\u88dd\u76f8\u95dc\u5957\u4ef6\u3002

    \u6211\u5011\u9810\u8a08\u8981\u4f7f\u7528GNU C++ Compiler\u9032\u884c\u7de8\u8b6f\uff0c\u4ee5\u53ca\u4f7f\u7528Visual studio code + clangd\u8207c++11\u7684\u6a19\u6e96\u64b0\u5beb\u7a0b\u5f0f\uff0c\u4e0b\u9762\u6703\u8a73\u8ff0\u5b89\u88dd\u6d41\u7a0b\u3002

    \u7576\u7136\uff0c\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528\u50cf\u662fdev c++\u3001codeblock\u9019\u985e\u7684\u8edf\u9ad4\u9032\u884c\u64b0\u5beb\uff0c\u53ea\u4e0d\u904e\u6709\u4e00\u9ede\u9700\u8981\u6ce8\u610f\uff0c\u820a\u7248\u7684dev c++\u9810\u8a2d\u6c92\u6709\u555f\u7528c++11\u6a19\u6e96\u7684\u652f\u63f4\uff0c\u4f60\u5fc5\u9808\u8981\u5728\u8a2d\u5b9a\u88e1\u9762\u5c0b\u627e\u958b\u555f\u7684\u65b9\u5f0f\u3002

    "},{"location":"fundamental/cpp/create_env/#windows","title":"Windows","text":"

    GNU C++ Compiler (G++)\u672c\u8eab\u662f\u6c92\u6709\u652f\u63f4Windows\u7684\uff0c\u4f46\u6211\u5011\u53ef\u4ee5\u900f\u904e\u4f7f\u7528wsl2\u6216\u8005\u5225\u4eba\u7528\u597d\u7684\u79fb\u690d\u7248\u672c\u9032\u884c\u4f7f\u7528\uff0c\u9019\u908a\u6211\u5011\u6703\u5b89\u88dd\u5225\u4eba\u5beb\u597d\u7684\u79fb\u690d\u7248\u3002

    "},{"location":"fundamental/cpp/create_env/#1mingw","title":"1.\u4e0b\u8f09\u4e26\u5b89\u88ddmingw","text":"
    1. \u524d\u5f80\u9019\u500b\u9023\u7d50\u5b89\u88ddmingw
    2. \u52fe\u9078 mingw32-gcc-g++
    3. installation > apply change
    4. \u6309\u4e0bapply\u5b89\u88dd

    "},{"location":"fundamental/cpp/create_env/#2","title":"2. \u52a0\u5165\u74b0\u5883\u8b8a\u6578","text":"
    1. \u5c0b\u627e\u5b89\u88dd\u4f4d\u7f6e\uff0c\u4ee5\u6211\u70ba\u4f8b\uff0c\u662f\u5b89\u88dd\u5728C:\\MinGW\u88e1\u9762\uff0c\u627e\u5230\u88e1\u9762\u7684bin\u8cc7\u6599\u593e\uff0c\u9ede\u9032\u53bb\u4e26\u8907\u88fd\u8def\u5f91\u3002
    2. \u641c\u5c0b\u74b0\u5883\u8b8a\u6578\uff0c\u4e26\u9032\u53bb\u7de8\u8f2f\u74b0\u5883\u8b8a\u6578\u3002
    3. \u9ede\u5165 \u9032\u968e >\u74b0\u5883\u8b8a\u6578\uff0c\u4e26\u5728Path\u4e2d\u8cbc\u4e0a\u525b\u624d\u8907\u88fd\u7684\u8b8a\u6578\uff0c\u7136\u5f8c\u4fdd\u5b58\u9000\u51fa\u3002

    "},{"location":"fundamental/cpp/create_env/#3","title":"3. \u6e2c\u8a66\u6307\u4ee4","text":"

    \u958b\u555f\u63d0\u793a\u547d\u4ee4\u5b57\u5143\u5f8c\uff0c\u6253\u5165g++ -v\uff0c\u5982\u679c\u6709\u7248\u672c\u8a0a\u606f\u4ee3\u8868\u5b89\u88dd\u6210\u529f\u3002

    "},{"location":"fundamental/cpp/create_env/#macos","title":"macOS","text":"

    macos\u672c\u8eab\u5c31\u6709\u63d0\u4f9bclangd\u4f5c\u70ba\u7de8\u8b6f\u5668\u4f7f\u7528\uff0c\u5728\u5b89\u88ddxcode\u5f8c\u61c9\u8a72\u5c31\u53ef\u4ee5\u4f7f\u7528\uff0c\u5982\u679c\u9084\u662f\u9700\u8981GNU C++ Compiler\uff0c\u8acb\u53c3\u8003\u4e0b\u9762\u6b65\u9a5f\u3002

    "},{"location":"fundamental/cpp/create_env/#1homwbrew","title":"1.\u5b89\u88ddhomwbrew\u5957\u4ef6\u7ba1\u7406\u5668","text":"

    \u6839\u64da\u5b98\u7db2\u7684\u6307\u793a\u5b89\u88ddhomebrew\u3002

    "},{"location":"fundamental/cpp/create_env/#2g","title":"2.\u4f7f\u7528\u7ba1\u7406\u5668\u5b89\u88ddg++\u5957\u4ef6","text":"
    1. \u5148\u4f7f\u7528brew search gcc\u641c\u5c0b\u76f8\u95dc\u5957\u4ef6
    2. \u4f7f\u7528 brew install gcc\u5b89\u88ddCompiler
    3. \u4f7f\u7528gcc-13 -v\u6216g++-13\u78ba\u8a8d\u662f\u5426\u6210\u529f\u5b89\u88dd

    Warning

    \u8acb\u6ce8\u610f\uff0c\u5728macos\u4e0a\u9810\u8a2d\u4f7f\u7528\u7684g++\u6307\u4ee4\u70baclang\u800c\u4e0d\u662fGNU C++ Compiler\uff0c\u8acb\u6539\u4f7f\u7528g++-XX \u4f86\u64cd\u4f5cg++\u7de8\u8b6f\u5668\u3002

    "},{"location":"fundamental/cpp/create_env/#visual_studio_code","title":"Visual Studio Code","text":""},{"location":"fundamental/cpp/create_env/#1_visual_studio_code","title":"1. \u5b89\u88ddVisual Studio Code","text":"

    \u524d\u5f80\u9019\u500b\u7db2\u7ad9\u4e0b\u8f09\u5c6c\u65bc\u4f60\u7cfb\u7d71\u7684visual studio code\u5b89\u88dd\u6a94\u3002

    "},{"location":"fundamental/cpp/create_env/#2_extension","title":"2. \u5b89\u88dd extension","text":"
    1. \u9ede\u5165extension\u9801\u9762\u5206\u5225\u5b89\u88ddC/C++ clangd \u9019\u5169\u500bextension\uff0c\u4e26\u91cd\u555fvscode
    2. \u4f60\u53ef\u80fd\u9047\u5230\u9019\u6a23\u7684\u8b66\u544a\u8a0a\u606f\uff0c\u8acb\u6309\u4e0b Disable Intellisence
    "},{"location":"fundamental/cpp/create_env/#_1","title":"\u5176\u4ed6","text":"

    \u5982\u679c\u9047\u5230\u5b57\u9ad4\u975e\u7b49\u5bec\uff0c\u8acb\u5c0b\u627e\u4e00\u500b\u7b49\u5bec\u5b57\u9ad4\u4e26\u4f7f\u7528\uff0c\u7b49\u5bec\u5b57\u9ad4\u53ef\u4ee5\u8b93\u4f60\u7684\u7a0b\u5f0f\u78bc\u53ef\u8b80\u6027\u66f4\u4f73\u3002

    "},{"location":"fundamental/cpp/hello_world/","title":"1. Hello World","text":""},{"location":"fundamental/cpp/hello_world/#hello_world","title":"Hello World (\u8f38\u51fa)","text":""},{"location":"fundamental/cpp/hello_world/#_1","title":"\u521d\u5b78\u8005\u7684\u7b2c\u4e00\u6b65","text":"

    \u9996\u5148\uff0c\u8acb\u5728vscode (Visual studio code)\u4e2d\u65b0\u589e\u4e00\u500b\u540d\u70bahello_world.cpp\uff0c\u4e26\u6253\u5165\u4e0b\u5217\u7a0b\u5f0f\u78bc\u3002

    #include <iostream>\n\nusing namespace std;\n\nint main(){\n    cout << \"hello world!\" << endl;\n    return 0;\n}\n
    \u78ba\u8a8d\u597d\u5b58\u6a94\u904e\u5f8c\uff0c\u6309\u4e0b\u53f3\u4e0a\u89d2\u7684\u57f7\u884c\u6309\u9375\uff0c\u4f60\u5c31\u6703\u6210\u529f\u770b\u5230\u4f60\u5beb\u7684\u7b2c\u4e00\u652f\u7a0b\u5f0f\u3002

    \u63a5\u8457\uff0c\u6211\u5011\u5c07\u66f4\u6df1\u5165\u8a0e\u8ad6\u9019\u6bb5\u7a0b\u5f0f\uff0c\u5230\u5e95\u767c\u751f\u4e86\u4ec0\u9ebc\u4e8b\u60c5\u3002

    "},{"location":"fundamental/cpp/hello_world/#hello_world_1","title":"Hello World\u7a0b\u5f0f\u89e3\u91cb","text":"

    \u5728\u9019\u6bb5\u7a0b\u5f0f\u4e2d\uff0c\u5df2\u7d93\u6709\u8a31\u591a\u7a0d\u5fae\u8907\u96dc\u7684\u6982\u5ff5\uff0c\u5148\u5225\u6015\uff0c\u6211\u5011\u5c31\u53ea\u8981\u4e86\u89e3\u5230:

    1. \u7a0b\u5f0f\u4e00\u5b9a\u662f\u5f9eint main(){......}\u88e1\u9762\u958b\u59cb\u57f7\u884c\u7684
    2. \u6700\u5f8c\u4e00\u5b9a\u6703\u6709\u500breturn 0; \u4ee3\u8868\u7a0b\u5f0f\u6210\u529f\u7d50\u675f\u3002

    \u8b93\u6211\u5011\u7126\u9ede\u653e\u5728\u7b2c\u516d\u884c:

    #include <iostream>\n\nusing namespace std;\n\nint main(){\n    cout << \"hello world!\" << endl;\n    return 0;\n}\n

    \u9019\u908a\u6709\u4e86\u6211\u5011\u7684\u7b2c\u4e00\u652f\u7a0b\u5f0f\uff0c\u4f60\u53ef\u4ee5\u628acout\u7576\u6210\u96fb\u8166\u87a2\u5e55\u7684\u6587\u5b57\u5370\u8868\u6a5f\uff0c\u628a<<\u7576\u6210\u50b3\u905e\u7684\u7bad\u982d\uff0c\u800c\u9019\u6bb5\u7a0b\u5f0f\u5c31\u662f\u8981\u628a\u9019\u6bb5\u5b57\u50b3\u7d66\u96fb\u8166\u5370\u51fa\u3002

    \u9019\u908a\u7684endl\u4ee3\u8868\u8457\u63db\u884c\u7684\u610f\u601d\uff0c\u900f\u904e<<\u50b3\u7d66\u96fb\u8166\u87a2\u5e55\u7684\u6587\u5b57\u5370\u8868\u6a5f\u3002

    \u53e6\u5916\u4e00\u500b\u5beb\u6cd5

    \u9019\u908a\u63d0\u4f9b\u53e6\u5916\u4e00\u500b\u63db\u884c\u7684\u5beb\u6cd5\uff0c\u5177\u9ad4\u5dee\u7570\u5728\u719f\u6089\u8a9e\u6cd5\u5f8c\uff0c\u6703\u5728\u53e6\u5916\u4e00\u7bc7\u6587\u7ae0\u505a\u8aaa\u660e\u3002

    #include <iostream>\n\nusing namespace std;\n\nint main(){\n    cout << \"hello world!\\n\";\n    return 0;\n}\n
    \\n\u70ba\u63db\u884c\u5b57\u5143\uff0c\u5728\u5b57\u5143\u4e2d\u6709\u8a31\u591a\u5b57\u5143\u6703\u6709\u7279\u5b9a\u529f\u7528\uff0c\u6703\u4ee5\\\u958b\u982d\uff0c\u9023\u7d50\u4e00\u500b\u5b57\u6bcd\u6216\u6578\u5b57\uff0c\u4ee3\u8868\u8457\u8df3\u812b\u5b57\u5143\uff0c\u4f5c\u70ba\u7279\u6b8a\u7528\u9014\u4f7f\u7528\u3002

    \u7d30\u5fc3\u5982\u4f60\uff0c\u9019\u662f\u53c8\u8981\u63d0\u554f\u4e86\uff0c\u5206\u865f;\u53c8\u4ee3\u8868\u4ec0\u9ebc\u610f\u601d\uff1f

    \u5206\u865f;\u662f\u544a\u8a34\u96fb\u8166\u8aaa\uff0c\u9019\u4e9b\u6307\u4ee4\u8ddf\u4e0b\u4e00\u500b\u5b57\u5143\u6216\u4e0b\u4e00\u884c\u662f\u5206\u958b\u7684\uff0c\u4e0d\u8981\u628a\u4ed6\u9023\u5728\u4e00\u8d77\uff0c\u4e5f\u56e0\u70ba\u6709\u9019\u6771\u897f\uff0c\u6211\u5011\u7a0b\u5f0f\u53ef\u4ee5\u9019\u6a23\u5beb\u3002

    #include <iostream>\n\nusing namespace std;\n\nint main(){\n    cout << \"hello world!\\n\"; cout << endl;\n    return 0;\n}\n

    Danger

    \u5341\u5206\u4e0d\u5efa\u8b70\u4f60\u9019\u6a23\u5beb\uff0c\u5c0d\u65bc\u7a0b\u5f0f\u719f\u7df4\u7684\u4eba\u4f86\u8aaa\uff0c\u9019\u6a23\u7684\u6392\u7248\uff0c\u7a0b\u5f0f\u78bc\u8b80\u8d77\u4f86\u6703\u975e\u5e38\u75db\u82e6\uff0c\u5c0d\u65bc\u521d\u5b78\u8005\uff0c\u5247\u5bb9\u6613\u8aa4\u89e3\u7a0b\u5f0f\u78bc\u3002

    "},{"location":"fundamental/cpp/hello_world/#_2","title":"\u52a0\u5165\u8b8a\u6578 (\u8f38\u5165)","text":""},{"location":"fundamental/cpp/hello_world/#_3","title":"\u8b80\u53d6\u5b57\u4e32","text":"
    #include <iostream>\n\nusing namespace std;\n\nint main(){\n    string str;\n    cin >> str;\n    cout << str << endl;\n    return 0;\n}\n

    \u6309\u4e0b\u57f7\u884c\uff0c\u6253\u5165\u96a8\u4fbf\u4e00\u4e32\u6587\u5b57\uff0c\u6309\u4e0benter\uff0c\u4f60\u6703\u767c\u73fe\u4f60\u6253\u7684\u6587\u5b57\u88ab\u5370\u5728\u87a2\u5e55\u4e0a\u3002

    "},{"location":"fundamental/cpp/hello_world/#_4","title":"\u8b80\u53d6\u6578\u5b57","text":"

    \u5047\u5982\u4eca\u5929\u6211\u5011\u8f38\u5165\u7684\u6578\u5b57\uff0c\u5247\u7a0b\u5f0f\u78bc\u6539\u6210\u9019\u6a23:

    #include <iostream>\n\nusing namespace std;\n\nint main(){\n    int temp;\n    cin >> temp;\n    cout << temp << endl;\n    return 0;\n}\n

    \u6309\u4e0b\u57f7\u884c\uff0c\u6253\u5165\u96a8\u4fbf\u4e00\u500b\u6578\u5b57\uff0c\u6309\u4e0benter\uff0c\u4f60\u6703\u767c\u73fe\u4f60\u6253\u7684\u4e00\u4e32\u6578\u5b57\u88ab\u5370\u5728\u87a2\u5e55\u4e0a\u3002

    Info

    \u5982\u679c\u4eca\u5929\u6253\u5165\u7684\u6578\u5b57\u975e\u5e38\u975e\u5e38\u7684\u5927\uff0c\u4f60\u53ef\u80fd\u6703\u767c\u73fe\u5370\u51fa\u4f86\u7684\u6578\u5b57\u8ddf\u6253\u5165\u7684\u6578\u5b57\u4e0d\u4e00\u6a23\uff0c\u5176\u539f\u56e0\u662f\u6ea2\u4f4d\uff0c\u9019\u9ede\u6211\u5011\u6703\u5728\u4e0b\u4e00\u7ae0\u8ac7\u5230\u5176\u539f\u56e0\u8207\u89e3\u6cd5\u3002

    "},{"location":"fundamental/cpp/hello_world/#_5","title":"\u8f38\u5165\u7a0b\u5f0f\u89e3\u91cb","text":"

    \u6b63\u5982cout\u4e00\u6a23\uff0c\u4f60\u53ef\u4ee5\u628acin\u7576\u6210\u4f60\u7684\u9375\u76e4\uff0c\u900f\u904e>>\u544a\u8a34\u96fb\u8166\u5f9e\u9375\u76e4\u8f38\u5165\u81f3\u53f3\u908a\u7684\u8b8a\u6578\u3002

    \u5e38\u898b\u7684\u8aa4\u5340

    \u5c0d\u65bc\u521d\u5b78\u8005\u4f86\u8aaa\uff0c\u53ef\u80fd\u6703\u4e0d\u5c0f\u5fc3\u5beb\u51fa\u9019\u6a23\u7684\u7a0b\u5f0f\uff1a

    #include <iostream>\n\nusing namespace std;\n\nint main(){\n    int temp1,temp2;\n    cin << temp1 << temp2;\n    cout << temp1 << \"!=\" << temp2 << endl;\n    return 0;\n}\n

    \u6b64\u6642\u4f60\u6703\u767c\u73fe\u7121\u6cd5\u7de8\u8b6f\uff0c\u5176\u539f\u56e0\u662f\u4f60\u7684cin\u7684<<\u61c9\u8a72\u8981\u662f>>\u624d\u5c0d \u3002

    \u5e38\u898b\u7684\u932f\u8aa4\u4e5f\u5305\u62ec\u4e0b\u9762\u7684\u4f8b\u5b50\uff1a

    1. cout\u7684<< \u65b9\u5411\u932f\u8aa4
      #include <iostream>\n\nusing namespace std;\n\nint main(){\n    int temp1,temp2;\n    cin >> temp1 >> temp2;\n    cout >> temp1 >> temp2;\n    return 0;\n}\n
    2. cout\u7684\u4f4d\u7f6e\u932f\u8aa4

      #include <iostream>\n\nusing namespace std;\n\nint main(){\n    \"error\" >> cout;\n    return 0;\n}\n
      cout \u53ea\u80fd\u653e\u5728\u5de6\u908a\u554a\u3002

    3. cin\u7684\u4f4d\u7f6e\u932f\u8aa4

      #include <iostream>\n\nusing namespace std;\n\nint main(){\n    int a;\n    a << cin;\n    return 0;\n}\n
      \u539f\u56e0\u540c\u4e0a\uff0ccin\u53ea\u80fd\u653e\u5728\u5de6\u908a\u554a\u3002

    "},{"location":"fundamental/cpp/hello_world/#_6","title":"\u9023\u7e8c\u8b80\u53d6\u6578\u5b57/\u5b57\u4e32","text":"

    \u5047\u5982\u4eca\u5929\u6211\u5011\u8f38\u5165\u7684\u4e00\u9023\u6578\u5b57\uff0c\u5247\u7a0b\u5f0f\u78bc\u6539\u6210\u9019\u6a23\u3002

    #include <iostream>\n\nusing namespace std;\n\nint main(){\n    int temp1;\n    string temp2;\n    cin >> temp1 >> temp2;\n    cout << temp1 << \"!=\" << temp2 << endl;\n    return 0;\n}\n
    input
    1234 4321\n
    output
    1234!=4321\n

    \u4f60\u6703\u767c\u73fe\u4e00\u4ef6\u4e8b\u60c5\uff0ccin\u662f\u900f\u904e\u7a7a\u683c\u6216\u8005\u63db\u884c\u4f86\u5206\u958b\u7684\uff0c\u4eca\u5929\u5982\u679c\u60f3\u8981\u8b80\u53d6\u4e00\u884c\uff0c\u8acb\u53c3\u8003\u4e0b\u65b9\u7a0b\u5f0f\u3002

    "},{"location":"fundamental/cpp/hello_world/#_7","title":"\u8b80\u53d6\u4e00\u884c","text":"

    \u7a0b\u5f0f\u78bc\u5982\u4e0b\uff0c\u5176\u4e2dtemp2\u8acb\u6539\u6210\u8b8a\u6578\u7684\u540d\u7a31\u3002

    #include <iostream>\n\nusing namespace std;\n\nint main(){\n    string temp2;\n    getline(cin,temp2);\n    cout << temp2 << endl;\n    return 0;\n}\n
    "},{"location":"fundamental/cpp/hello_world/#practice","title":"Practice","text":"

    \u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u4f60\u5b78\u5230\u4e86:

    Info

    1. \u5982\u4f55\u4f7f\u7528 cout\u8207cin
    2. \u63a5\u89f8\u8b8a\u6578\u7684\u6982\u5ff5\u3002

    \u90a3\u73fe\u5728\u4f60\u53ef\u4ee5\u8a66\u8a66\u770b\u4ee5\u4e0b\u7684\u984c\u76ee\u4e86\u3002

    ZeroJudge - a001. \u54c8\u56c9

    Reference code
    #include <iostream>\n\nint main(){\n    string word;\n    cin >> word;\n    cout << \"hello, \" << word << endl;\n\n    return 0;\n}\n
    "},{"location":"fundamental/python/","title":"Python","text":"

    \u55e8\uff0c\u6211\u662f @cheung4843\uff0c\u662fPython\u7cfb\u5217\u7684\u4f5c\u8005\u3002\u5728\u4e00\u958b\u59cb\u57fa\u790e\u8a9e\u6cd5\u7684\u90e8\u5206\u6703\u6559\u5f97\u7279\u5225\u8a73\u7d30\uff0c\u6587\u7ae0\u4e2d\u7684\u5c08\u6709\u540d\u8a5e\u5c07\u6703\u4ee5\u9ec3\u8272\u8207\u7da0\u8272\u6a19\u793a\uff0c\u8acb\u4f60\u7a0d\u5fae\u6ce8\u610f\u4e00\u4e0b\uff0c\u82e5\u4e0d\u61c2\u4e5f\u6c92\u95dc\u4fc2\uff0c\u6211\u6703\u5728\u5f8c\u9762\u7ae0\u7bc0\u518d\u6b21\u63d0\u5230\u3002

    \u5728\u6bcf\u4e00\u500b\u5c0f\u7bc0\u7684\u5f8c\u9762\u90fd\u6703\u6709\u7b46\u8a18\u5340\u4ee5\u53ca\u554f\u984c\u5340\uff0c\u5c24\u5176\u662f\u554f\u984c\u5340\uff0c\u8acb\u4f60\u597d\u597d\u601d\u8003\u3002\u800c\u5728\u6bcf\u4e00\u7bc7\u6587\u7ae0\u6700\u5f8c\u90fd\u6703\u653e\u4e0a\u4e00\u4e9b\u7df4\u7fd2\u984c\uff0c\u8acb\u5617\u8a66\u5b8c\u6210\u4ed6\u5011!

    "},{"location":"fundamental/python/lists/","title":"Lists","text":""},{"location":"fundamental/python/lists/#introduction","title":"Introduction","text":"

    \u4e0d\u66c9\u5f97\u4f60\u770b\u5230\u9019\u88e1\u6709\u6c92\u6709\u767c\u73fe\uff0c\u6211\u5011\u5728\u524d\u9762\u7684\u7ae0\u7bc0\u4e2d\uff0c\u90fd\u662f\u7528\u4e00\u500b\u4e00\u500b\u7684\u8b8a\u6578\u4f86\u5132\u5b58\u8cc7\u6599\uff0c\u4f46\u662f\u5982\u679c\u6211\u5011\u8981\u5132\u5b58\u5f88\u591a\u7b46\u8cc7\u6599\uff0c\u9019\u6a23\u7684\u65b9\u5f0f\u5c31\u6703\u8b8a\u5f97\u5f88\u9ebb\u7169\u3002

    \u6240\u4ee5\u9019\u88e1\u8ddf\u4f60\u4ecb\u7d39 List(\u4e32\u5217)\uff0c\u5b83\u53ef\u4ee5\u8b93\u6211\u5011\u5132\u5b58\u5f88\u591a\u7b46\u8cc7\u6599\uff0c\u800c\u4e14\u53ef\u4ee5\u5132\u5b58\u4e0d\u540c\u7684\u8cc7\u6599\u578b\u614b\uff0c\u4f8b\u5982: \u6578\u5b57\u3001\u5b57\u4e32\u3001\u5e03\u6797\u503c\u7b49\u7b49\u3002

    "},{"location":"fundamental/python/lists/#create_a_list","title":"Create a list","text":"

    \u8981\u5efa\u7acb\u4e00\u500b List\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u4e2d\u62ec\u865f []\uff0c\u4e26\u5728\u4e2d\u62ec\u865f\u4e2d\u653e\u5165\u6211\u5011\u8981\u5132\u5b58\u7684\u8cc7\u6599\uff0c\u8cc7\u6599\u4e4b\u9593\u7528\u9017\u865f , \u9694\u958b\u3002

    \u4f86\u8209\u500b\u4f8b\u5b50\uff0c\u5efa\u7acb\u4e09\u500b List\uff0c\u4e00\u500b\u90fd\u5132\u5b58\u6574\u6578\uff0c\u4e00\u500b\u662f\u90fd\u5132\u5b58\u5b57\u4e32\uff1b\u6700\u5f8c\u4e00\u500b\u5247\u653e\u4e86\u4e0d\u540c\u7684\u8cc7\u6599\u578b\u614b\u3002

    numbers = [1, 2, 3, 4, 5]\nprint(numbers)\n\nwhat_i_learned = [\"C\", \"C++\", \"Python\", \"Java\", \"C#\", \"JavaScript\", \"TypeScript\"]\nprint(what_i_learned)\n\nstudent_info = [\"Sean\", 20, \"Computer Science\", 4.0, True, \"aLIEz\"]\nprint(student_info)\n\nprint(type(numbers), type(what_i_learned), type(student_info))\n
    ouput
    [1, 2, 3, 4, 5]\n['C', 'C++', 'Python', 'Java', 'C#', 'JavaScript', 'TypeScript']\n['Sean', 20, 'Computer Science', 4.0, True, 'aLIEz']\n<class 'list'> <class 'list'> <class 'list'>\n

    Sawano Hiroyuki - aLIEz Aldnoah.Zero Full Lyrics

    \u5982\u679c\u4f60\u6709\u5b78\u904e\u5176\u4ed6\u7684\u7a0b\u5f0f\u8a9e\u8a00\uff0c\u4f60\u53ef\u80fd\u6703\u807d\u904e Array(\u9663\u5217)\uff0cList \u5c31\u662f Python \u4e2d\u7684 Array\uff0c\u4f46\u53c8\u66f4\u5f37\u5927\uff0c\u56e0\u70ba List \u53ef\u4ee5\u5132\u5b58\u4e0d\u540c\u7684\u8cc7\u6599\u578b\u614b\uff0c\u800c\u901a\u5e38 Array \u53ea\u80fd\u5132\u5b58\u4e00\u7a2e\u8cc7\u6599\u578b\u614b\u3002

    \u4f46 Python \u4e5f\u6709\u63d0\u4f9b\u771f\u6b63\u7684\u300c\u9663\u5217\u300d\uff0c\u4f46\u6211\u5148\u4e0d\u63d0\uff0c\u8acb\u4f60\u7a0d\u5fae\u6709\u500b\u5370\u8c61\u5c31\u597d\u3002

    \u984c\u5916\u8a71\uff0c\u7576\u521d\u5f9e C, C++, Java \u8f49\u5230 Python \u7684\u6642\u5019\uff0c\u771f\u5fc3\u89ba\u5f97\u600e\u9ebc\u53ef\u4ee5\u9019\u9ebc\u96a8\u4fbf\uff0c\u9023\u578b\u614b\u90fd\u4e0d\u7528\u5ba3\u544a\uff0c\u73fe\u5728\u89ba\u5f97\u771f\u9999\u3002

    \u4e0d\u66c9\u5f97\u4f60\u9084\u8a18\u4e0d\u8a18\u5f97\uff0c\u6211\u5011\u5728\u524d\u9762\u7684\u7ae0\u7bc0\u4e2d\uff0c\u6709\u63d0\u5230 range \u9019\u500b\u51fd\u5f0f\uff0c\u5b83\u53ef\u4ee5\u7522\u751f\u4e00\u500b\u6574\u6578\u7684\u5e8f\u5217\uff0c\u4f8b\u5982: range(5) \u6703\u7522\u751f\u4e00\u500b\u5f9e \\(0\\) \u5230 \\(4\\) \u7684\u6574\u6578\u5e8f\u5217\u3002

    list(range(5)) \u9019\u6a23\u5c31\u53ef\u4ee5\u5c07 range \u7269\u4ef6\u8f49\u63db\u6210 List\u3002

    x = range(5)\nprint(type(x))\nnumbers = list(x)\nprint(numbers)\n
    ouput
    <class 'range'>\n[0, 1, 2, 3, 4]\n

    \u90a3\u80fd\u5426\u628a\u5b57\u4e32\u8f49\u63db\u6210 List \u5462? \u7576\u7136\u53ef\u4ee5!

    x = \"Signals\"\nprint(type(x))\nwords = list(x)\nprint(words)\n
    ouput
    <class 'str'>\n['S', 'i', 'g', 'n', 'a', 'l', 's']\n

    Lazer Boomerang - Signals (Official Audio)

    \u518d\u4f86\u770b\u4e00\u500b\u4f8b\u5b50\uff0c\u5982\u4f55\u521d\u59cb\u5316\u4e00\u500b\u5143\u7d20\u90fd\u662f \\(0\\) \u7684\u4e32\u5217\u3002

    n = 5\nzeros = [0] * n\nprint(zeros)\n
    ouput
    [0, 0, 0, 0, 0]\n

    \u5982\u4f55\u5c07\u5169\u500b\u4e32\u5217\u5408\u4f75\u6210\u4e00\u500b\u4e32\u5217\u5462?

    a = [1, 2, 3]\nb = [4, 5, 6]\nc = a + b\nprint(c)\n
    ouput
    [1, 2, 3, 4, 5, 6]\n

    \u9084\u6709\u4e00\u500b\u65b9\u6cd5\uff0c\u5c31\u662f\u4f7f\u7528 extend \u9019\u500b\u65b9\u6cd5\uff0c\u9019\u5728\u5f8c\u9762\u6703\u4ecb\u7d39\u5230\u3002

    \u6211\u76f8\u4fe1\u4ee5\u4e0a\u9019\u4e9b\u4f8b\u5b50\u80fd\u8b93\u4f60\u6293\u5230\u4e00\u4e9b\u6982\u5ff5\uff0c\u63a5\u4e0b\u4f86\u5c07\u4ecb\u7d39\u4e00\u7cfb\u5217\u7684\u64cd\u4f5c\u8207\u65b9\u6cd5\uff0c\u8b93\u4f60\u66f4\u719f\u6089 List\u3002

    "},{"location":"fundamental/python/lists/#operations","title":"Operations","text":""},{"location":"fundamental/python/lists/#accessing_elements","title":"Accessing elements","text":"

    \u8981\u5b58\u53d6 List \u4e2d\u7684\u5143\u7d20\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u4e2d\u62ec\u865f []\uff0c\u4e26\u5728\u4e2d\u62ec\u865f\u4e2d\u653e\u5165\u5143\u7d20\u7684\u7d22\u5f15\u503c\uff0c\u7d22\u5f15\u503c\u5f9e \\(0\\) \u958b\u59cb\uff0c\u4e26\u4e14\u53ef\u4ee5\u4f7f\u7528\u8ca0\u6578\uff0c\u8ca0\u6578\u7684\u7d22\u5f15\u503c\u662f\u5f9e\u6700\u5f8c\u4e00\u500b\u5143\u7d20\u958b\u59cb\u7b97\u8d77\u3002

    numbers = [1, 2, 3, 4, 5]\n\n# First element\nprint(numbers[0])\n# Last element\nprint(numbers[-1])\nprint(numbers[4])\n
    ouput
    1\n5\n5\n

    \u8b93\u6211\u5011\u914d\u5408\u8ff4\u5708\u4f86\u5370\u51fa\u4e32\u5217\u4e2d\u7684\u5143\u7d20\u3002

    numbers = [1, 2, 3, 4, 5]\n\nfor i in range(len(numbers)):\n    print(numbers[i], end=' ')\n
    ouput
    1 2 3 4 5\n

    len \u9019\u500b\u51fd\u5f0f\u53ef\u4ee5\u53d6\u5f97\u4e32\u5217\u7684\u9577\u5ea6\uff0c\u4e5f\u5c31\u662f\u4e32\u5217\u4e2d\u5143\u7d20\u7684\u500b\u6578\u3002

    \u4e0d\u66c9\u5f97\u4f60\u9084\u8a18\u4e0d\u8a18\u5f97 Repetiton Structures - Foreach \u7684\u5167\u5bb9\uff0c\u6211\u5011\u7528\u9019\u500b\u6982\u5ff5\u4f86\u5370\u51fa\u4e32\u5217\u4e2d\u7684\u5143\u7d20\u3002

    numbers = [1, 2, 3, 4, 5]\n\nfor number in numbers:\n    print(number, end=' ')\n
    ouput
    1 2 3 4 5\n
    "},{"location":"fundamental/python/lists/#slicing","title":"Slicing","text":"

    \u5207\u7247(Slicing)\u53ef\u4ee5\u7528\u4f86\u53d6\u5f97\u4e32\u5217\u4e2d\u7684\u4e00\u90e8\u5206\uff0c\u4f8b\u5982:

    numbers = [1, 2, 3, 4, 5, 6]\n\nprint(numbers[0:4])\nprint(numbers[:4])\nprint(numbers[:-2])\nprint(numbers[1:3])\nprint(numbers[:6:2])\nprint(numbers[::-1])\nprint(numbers[:])\n
    ouput
    [1, 2, 3, 4]\n[1, 2, 3, 4]\n[1, 2, 3, 4]\n[2, 3]\n[1, 3, 5]\n[6, 5, 4, 3, 2, 1]\n[1, 2, 3, 4, 5, 6]\n

    @EditTime : 2024-01-31 21:56

    \u4f60\u5f88\u8070\u660e\uff0c\u61c9\u8a72\u767c\u73fe\u4e86\u7528\u6cd5\u8207 range \u4e00\u6a23\uff0c\u5206\u5225\u662f\u8d77\u59cb\u7d22\u5f15\u503c\u3001\u7d50\u675f\u7d22\u5f15\u503c\u3001\u9593\u9694\uff0c\u5982\u679c\u4e0d\u5beb\u7684\u8a71\uff0c\u9810\u8a2d\u503c\u5206\u5225\u662f \\(0\\)\u3001\u4e32\u5217\u9577\u5ea6\u3001\\(1\\)\u3002

    "},{"location":"fundamental/python/lists/#modifying_elements","title":"Modifying elements","text":"

    \u8981\u4fee\u6539\u4e32\u5217\u4e2d\u7684\u5143\u7d20\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u4e2d\u62ec\u865f []\uff0c\u4e26\u5728\u4e2d\u62ec\u865f\u4e2d\u653e\u5165\u5143\u7d20\u7684\u7d22\u5f15\u503c\uff0c\u7136\u5f8c\u518d\u6307\u5b9a\u65b0\u7684\u503c\u3002

    music_info = [\"Time_To_Pretend\", \"Lazer Boomerang\", \" 2019/4/26\", 1, False]\nmusic_info[0] = \"Time To Pretend\"\nmusic_info[3] = 2\nmusic_info[-1] = True\nprint(music_info)\n
    ouput
    ['Time To Pretend', 'Lazer Boomerang', ' 2019/4/26', 2, True]\n

    Lazer Boomerang - Time To Pretend (Official Audio)

    \u6211\u5011\u53ef\u4ee5\u4fee\u6539\u4e32\u5217\u4e2d\u7684\u503c\uff0c\u9019\u7a31\u70ba \u53ef\u8b8a\u52d5\u7684(mutable)\uff0c\u800c\u5b57\u4e32\u5247\u4e0d\u884c\uff0c\u9019\u7a31\u70ba \u4e0d\u53ef\u8b8a\u52d5\u7684(immutable)\u3002

    sad_cat = \"\ud83d\ude3f\"\nsad_cat[0] = \"\ud83d\ude38\"\n
    ouput
    TypeError: 'str' object does not support item assignment\n
    "},{"location":"fundamental/python/lists/#checking_elements","title":"Checking elements","text":"

    \u8981\u6aa2\u67e5\u4e32\u5217\u4e2d\u662f\u5426\u6709\u67d0\u500b\u5143\u7d20\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 in \u9019\u500b\u904b\u7b97\u5b50\u3002

    numbers = [1, 2, 3, 4, 5]\nprint(1 in numbers)\nprint(6 not in numbers)\n
    ouput
    True\nTrue\n

    Question

    \u5c0d\u65bc\u9577\u5ea6\u70ba \\(n\\) \u7684\u7121\u5e8f\u4e32\u5217\uff0c\u8981\u6aa2\u67e5\u67d0\u500b\u5143\u7d20\u662f\u5426\u5b58\u5728\u65bc\u4e32\u5217\u4e2d\uff0c\u6700\u58de\u7684\u60c5\u6cc1\u4e0b\uff0c\u9700\u8981\u6aa2\u67e5\u591a\u5c11\u6b21?

    \u7b54\u6848\u662f \\(n\\) \u6b21\u5594\uff0c\u56e0\u70ba\u4e00\u500b\u4e00\u500b\u627e\uff0c\u76f4\u5230\u627e\u5230\u6216\u662f\u627e\u5b8c\u70ba\u6b62\uff0c\u50cf\u662f\u4f8b\u5b50\u4e2d\u7684 6\u3002

    \u5728\u6f14\u7b97\u6cd5(Algorithm)\u7684\u7ae0\u7bc0\u4e2d\u6703\u63d0\u5230\u6642\u9593\u8907\u96dc\u5ea6(Time Complexity)\u9019\u500b\u89c0\u5ff5\uff0c\u9019\u88e1\u5c31\u5148\u7d66\u4f60\u4e00\u500b\u5370\u8c61\u5c31\u597d\u4e86~

    "},{"location":"fundamental/python/lists/#methods","title":"Methods","text":"

    \u4f86\u4ecb\u7d39\u4e00\u4e9b\u5e38\u7528\u7684\u4e32\u5217\u65b9\u6cd5\u3002

    "},{"location":"fundamental/python/lists/#append","title":"append","text":"

    append \u9019\u500b\u65b9\u6cd5\u53ef\u4ee5\u5728\u4e32\u5217\u7684\u6700\u5f8c\u9762\u65b0\u589e\u4e00\u500b\u5143\u7d20\u3002

    numbers = [1, 2, 3, 4, 5]\nnumbers.append(6)\nprint(numbers)\nnumbers.append([7, 8, 9])\nprint(numbers)\n
    ouput
    [1, 2, 3, 4, 5, 6]\n[1, 2, 3, 4, 5, 6, [7, 8, 9]]\n

    \u5e0c\u671b\u7b2c\u4e8c\u500b append \u6c92\u6709\u5687\u5230\u4f60\uff0c\u5b83\u53ef\u4ee5\u65b0\u589e\u4e00\u500b\u4e32\u5217\uff0c\u4f46\u662f\u9019\u500b\u4e32\u5217\u6703\u8b8a\u6210\u4e32\u5217\u4e2d\u7684\u4e00\u500b\u5143\u7d20\u3002\u5982\u679c\u4f60\u662f\u60f3\u8981\u628a 7\u30018\u30019 \u9019\u4e09\u500b\u5143\u7d20\u52a0\u5230\u4e32\u5217\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 extend \u9019\u500b\u65b9\u6cd5\u3002

    "},{"location":"fundamental/python/lists/#extend","title":"extend","text":"

    extend \u9019\u500b\u65b9\u6cd5\u53ef\u4ee5\u5728\u4e32\u5217\u7684\u6700\u5f8c\u9762\u65b0\u589e\u53e6\u4e00\u500b\u4e32\u5217\u4e2d\u7684\u5143\u7d20\u3002

    numbers = [1, 2, 3, 4, 5]\nnumbers.extend([6, 7, 8])\nprint(numbers)\n
    ouput
    [1, 2, 3, 4, 5, 6, 7, 8]\n
    "},{"location":"fundamental/python/lists/#pop","title":"pop","text":"

    pop \u9019\u500b\u65b9\u6cd5\u53ef\u4ee5\u79fb\u9664\u4e32\u5217\u4e2d\u7684\u5143\u7d20\uff0c\u4e26\u56de\u50b3\u88ab\u79fb\u9664\u7684\u5143\u7d20\u3002

    fruits = [\"apple\", \"banana\", \"cherry\", \"durian\", \"elderberry\"]\nprint(fruits.pop())\nprint(fruits)\nprint(fruits.pop(1))\nprint(fruits)\n
    ouput
    elderberry\n['apple', 'banana', 'cherry', 'durian']\nbanana\n['apple', 'cherry', 'durian']\n

    \u901a\u5e38\uff0c\u6211\u5011\u6703\u4f7f\u7528 pop \u4f86\u79fb\u9664\u4e32\u5217\u4e2d\u7684\u6700\u5f8c\u4e00\u500b\u5143\u7d20\uff0c\u56e0\u70ba\u9019\u6a23\u53ef\u4ee5\u907f\u514d\u7d22\u5f15\u503c\u8d85\u51fa\u7bc4\u570d\u7684\u932f\u8aa4\uff0c\u4f60\u4e5f\u53ef\u4ee5\u6307\u5b9a\u7d22\u5f15\u503c\uff0c\u4f86\u79fb\u9664\u4e32\u5217\u4e2d\u7684\u5143\u7d20\uff0c\u4f46\u4e0d\u5efa\u8b70\u3002

    "},{"location":"fundamental/python/lists/#clear","title":"clear","text":"

    clear \u9019\u500b\u65b9\u6cd5\u53ef\u4ee5\u79fb\u9664\u4e32\u5217\u4e2d\u7684\u6240\u6709\u5143\u7d20\u3002

    numbers = [1, 2, 3, 4, 5]\nnumbers.clear()\nprint(numbers)\n
    ouput
    []\n
    "},{"location":"fundamental/python/lists/#reverse","title":"reverse","text":"

    reverse \u9019\u500b\u65b9\u6cd5\u53ef\u4ee5\u53cd\u8f49\u4e32\u5217\u3002

    numbers = [1, 2, 3, 4, 5]\nnumbers.reverse()\nprint(numbers)\n
    ouput
    [5, 4, 3, 2, 1]\n
    "},{"location":"fundamental/python/lists/#sort","title":"sort","text":"

    sort \u9019\u500b\u65b9\u6cd5\u53ef\u4ee5\u6392\u5e8f\u4e32\u5217\uff0c\u9810\u8a2d\u662f\u7531\u5c0f\u5230\u5927\u6392\u5e8f\uff0c\u5982\u679c\u8981\u7531\u5927\u5230\u5c0f\u6392\u5e8f\uff0c\u53ef\u4ee5\u6307\u5b9a reverse=True\u3002

    numbers = [5, 4, 3, 2, 1]\nnumbers.sort()\nprint(numbers)\nnumbers.sort(reverse=True)\nprint(numbers)\n
    ouput
    [1, 2, 3, 4, 5]\n[5, 4, 3, 2, 1]\n

    \u751a\u81f3\u4f60\u53ef\u4ee5\u8a2d\u5b9a key\uff0c\u4f86\u6c7a\u5b9a\u6392\u5e8f\u7684\u4f9d\u64da\uff0c\u4f8b\u5982: key=len\uff0c\u5c31\u662f\u6839\u64da\u5143\u7d20 x \u7684 len(x) \u4f86\u6392\u5e8f\u3002

    fruits = [\"apple\", \"banana\", \"watermelon\", \"pineapple\"]\nfruits.sort(key=len)\nprint(fruits)\n
    ouput
    ['apple', 'banana', 'pineapple', 'watermelon']\n
    "},{"location":"fundamental/python/lists/#copy","title":"copy","text":"

    copy \u9019\u500b\u65b9\u6cd5\u56de\u50b3\u4e00\u500b\u6dfa\u8907\u88fd(Shallow Copy)\u7684\u4e32\u5217\u3002

    numbers = [1, 2, 3, 4, 5]\nnumbers_copy = numbers.copy()\nprint(numbers_copy)\nprint(numbers)\n\nprint(\"After changing numbers[1]\")\n\nnumbers[1] = 10\nprint(numbers_copy)\nprint(numbers)\n
    ouput
    [1, 2, 3, 4, 5]\n[1, 2, 3, 4, 5]\nAfter changing numbers[1]\n[1, 2, 3, 4, 5]\n[1, 10, 3, 4, 5]\n

    \u9019\u500b\u4f8b\u5b50\u9084\u4e0d\u80fd\u770b\u51fa\u6dfa\u8907\u88fd\uff0c\u4fee\u6539\u4e86 numbers \u7684\u7b2c\u4e8c\u500b\u5143\u7d20\uff0cnumbers_copy \u4e0d\u6703\u8ddf\u8457\u6539\u8b8a\u3002

    numbers = [1, [2, 3], 4, 5]\nnumbers_copy = numbers.copy()\nprint(numbers_copy)\nprint(numbers)\n\nprint(\"After changing numbers[1]\")\n\nnumbers[1][0] = 6\nprint(numbers_copy)\nprint(numbers)\n
    ouput
    [1, [2, 3], 4, 5]\n[1, [2, 3], 4, 5]\nAfter changing numbers[1]\n[1, [6, 3], 4, 5]\n[1, [6, 3], 4, 5]\n

    \u90a3\u4ec0\u9ebc\u53c8\u662f\u6df1\u8907\u88fd(Deep Copy)\u5462? \u9019\u500b\u5c31\u8981\u7b49\u5230\u6211\u5011\u5b78\u5230\u7269\u4ef6\u5c0e\u5411\u7a0b\u5f0f\u8a2d\u8a08(Object-Oriented Programming)\u7684\u6642\u5019\uff0c\u518d\u4f86\u8ddf\u4f60\u4ecb\u7d39\uff0c\u6211\u4e0d\u61c9\u8a72\u6316\u5751\u7684\u3002

    \u9084\u6709\u66f4\u591a\u65b9\u6cd5\uff0c\u4f60\u53ef\u4ee5\u53c3\u8003 Python Documentation - List\uff0c\u4f46\u6211\u4e0a\u9762\u4ecb\u7d39\u7684\u65b9\u6cd5\uff0c\u4f60\u81f3\u5c11\u8981\u6703\uff0c\u4f60\u4e5f\u8981\u990a\u6210\u770b\u5b98\u65b9\u6587\u4ef6\u7684\u7fd2\u6163\u3002

    "},{"location":"fundamental/python/lists/#list_comprehension","title":"List Comprehension","text":"

    \u4e32\u5217\u7d9c\u5408\u904b\u7b97(List comprehension)\u8b93\u4f60\u7528\u4e00\u884c\u7a0b\u5f0f\u78bc\uff0c\u5c31\u53ef\u4ee5\u5efa\u7acb\u51fa\u64c1\u6709\u67d0\u9805\u6027\u8cea\u5143\u7d20\u7684\u4e32\u5217\u3002

    \u8209\u500b\u4f8b\u5b50\uff0c\u8f38\u5165\u4e00\u500b\u4e32\u5217 a\uff0c\u8f38\u51fa\u4e00\u500b\u4e32\u5217 b\uff0c\u5176\u4e2d b[i] = a[i] ** 2\uff0c\u4e5f\u5c31\u662f b \u4e2d\u7684\u5143\u7d20\u90fd\u662f\u5c0d\u61c9 a \u5143\u7d20\u7684\u5e73\u65b9\u3002

    \u6211\u5011\u5148\u4f7f\u7528\u8ff4\u5708\u4f86\u5be6\u4f5c:

    a = [1, 2, 3, 4, 5]\nb = []\n\nfor num in a:\n    b.append(num ** 2)\n\nprint(b)\n
    ouput
    [1, 4, 9, 16, 25]\n

    \u518d\u4f86\u4f7f\u7528\u4e32\u5217\u7d9c\u5408\u904b\u7b97:

    a = [1, 2, 3, 4, 5]\nb = [num ** 2 for num in a]\n\nprint(b)\n
    ouput
    [1, 4, 9, 16, 25]\n

    \u975e\u5e38\u5730\u512a\u96c5\uff0c\u6211\u5011\u518d\u4f86\u770b\u4e00\u500b\u4f8b\u5b50\uff0c\u8f38\u5165\u4e00\u500b\u4e32\u5217 a\uff0c\u8f38\u51fa\u4e00\u500b\u4e32\u5217 b\uff0c\u5176\u4e2d b \u7684\u5143\u7d20\u90fd\u662f a \u5143\u7d20\u4e2d\u7684\u5076\u6578\u3002

    a = [1, 2, 3, 4, 5]\nb = [num for num in a if num % 2 == 0]\n\nprint(b)\n
    ouput
    [2, 4]\n

    \u9084\u8a18\u5f97 Operators - Bonus: map for input \u63d0\u5230\u7684 map \u55ce?

    \u5148\u4f86\u8907\u7fd2\u4e00\u4e0b\uff0cmap \u53ef\u4ee5\u5c07\u4e00\u500b\u51fd\u5f0f\u5957\u7528\u5230\u4e00\u500b\u5e8f\u5217\u7684\u6bcf\u4e00\u500b\u5143\u7d20\uff0c\u4e26\u56de\u50b3\u4e00\u500b map \u7269\u4ef6\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 list \u5c07 map \u7269\u4ef6\u8f49\u63db\u6210\u4e32\u5217\u3002

    a = [\"1\", \"2\", \"3\", \"4\", \"5\"]\nb = map(int, a)\nprint(type(b))\n\nc = list(b)\nprint(c)\n
    ouput
    <class 'map'>\n[1, 2, 3, 4, 5]\n

    @EditTime : 2024-02-01 23:21

    \u90a3\u80fd\u4e0d\u80fd\u7528\u4e32\u5217\u7d9c\u5408\u904b\u7b97\u4f86\u5be6\u4f5c\u5462?

    a = [\"1\", \"2\", \"3\", \"4\", \"5\"]\nb = [int(num) for num in a]\nprint(b)\n
    ouput
    [1, 2, 3, 4, 5]\n

    \u7b54\u6848\u662f\u80af\u5b9a\u7684\u3002

    \u9084\u6709\u5f88\u591a\u61c9\u7528\uff0c\u4f8b\u5982: \u4e32\u5217\u4e2d\u7684\u5143\u7d20\u90fd\u662f\u5c0f\u5beb\uff0c\u6211\u5011\u60f3\u8981\u628a\u5b83\u5011\u8f49\u63db\u6210\u5927\u5beb\u3002

    lowercase = [\"a\", \"b\", \"c\", \"d\", \"e\"]\nuppercase = [letter.upper() for letter in lowercase]\nprint(uppercase)\n
    ouput
    ['A', 'B', 'C', 'D', 'E']\n

    \u6ce8\u610f\u56c9\uff0c\u9019\u908a\u7528\u5230\u7684\u662f\u65b9\u6cd5\u5594\u3002

    "},{"location":"fundamental/python/lists/#nested_lists","title":"Nested Lists","text":"

    \u5de2\u72c0\u4e32\u5217(Nested Lists)\uff0c\u5c31\u662f\u4e32\u5217\u4e2d\u7684\u5143\u7d20\u4e5f\u662f\u4e32\u5217\u3002

    "},{"location":"fundamental/python/lists/#2d","title":"2D","text":"

    \u5148\u4f86\u8209\u4e00\u500b\u4f60\u53ef\u80fd\u807d\u904e\u7684\u540d\u8a5e\uff0c\u4e8c\u7dad\u9663\u5217(2D Array)\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u5de2\u72c0\u4e32\u5217\u4f86\u5be6\u4f5c\u4e8c\u7dad\u9663\u5217\uff0c\u4f8b\u5982\u5169\u500b \\(3 \\times 3\\) \u7684\u4e8c\u7dad\u9663\u5217\uff0c\u4f86\u9032\u884c\u77e9\u9663\u52a0\u6cd5\u3002

    matrix_1 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]\nmatrix_2 = [[9, 8, 7], [6, 5, 4], [3, 2, 1]]\n\nmatrix_3 = [[0 for i in range(3)] for j in range(3)]\n\nfor i in range(3):\n    for j in range(3):\n        matrix_3[i][j] = matrix_1[i][j] + matrix_2[i][j]\n\nprint(matrix_3)\n
    ouput
    [[10, 10, 10], [10, 10, 10], [10, 10, 10]]\n

    \u6211\u5e0c\u671b matrix_3 \u7684\u521d\u59cb\u5316\u6c92\u6709\u5687\u5230\u4f60\uff0c\u8acb\u4f60\u628a [0 for i in range(3)] \u7576\u6210\u4e00\u500b\u6574\u9ad4 E\uff0c\u518d\u628a [E for j in range(3)] \u7576\u6210\u4e00\u500b\u6574\u9ad4\uff0c\u9019\u6a23\u5c31\u4e0d\u6703\u89ba\u5f97\u5f88\u8907\u96dc\u4e86\uff0ci, j \u90fd\u53ea\u662f\u8a08\u6578\u7528\u7684\u800c\u5df2\uff0c\u4e0d\u8981\u88ab\u5b83\u5011\u5687\u5230\u3002

    "},{"location":"fundamental/python/lists/#jagged","title":"Jagged","text":"

    \u92f8\u9f52\u72c0\u4e32\u5217(Jagged Lists)\uff0c\u5c31\u662f\u5141\u8a31\u5de2\u72c0\u4e32\u5217\u4e2d\u7684\u5143\u7d20\u7684\u9577\u5ea6\u4e0d\u4e00\u6a23\u3002

    \u984c\u5916\u8a71\uff0c\u4e4b\u524d\u5728\u5b78 C \u7684\u6642\u5019\uff0c\u53ea\u80fd\u7528\u6307\u6a19\u4f86\u5be6\u4f5c\uff0c\u4f46\u7528\u8d77\u4f86\u771f\u7684\u5f88\u9ebb\u7169\u3002

    jagged = [[1, 2, 3], [4, 5], [6, 7, 8, 9]]\n\nfor row in jagged:\n    for elem in row:\n        print(elem, end=' ')\n    print()\n
    ouput
    1 2 3 \n4 5 \n6 7 8 9 \n

    \u5e0c\u671b\u9019\u500b\u8ff4\u5708\u7684\u5beb\u6cd5\u4e0d\u6703\u5687\u5230\u4f60\uff0crow \u662f jagged \u4e2d\u7684\u4e00\u500b\u5143\u7d20\uff0c\u4e5f\u5c31\u662f\u4e00\u500b\u4e32\u5217\uff0celem \u662f row \u4e2d\u7684\u4e00\u500b\u5143\u7d20\uff0c\u4e5f\u5c31\u662f\u4e00\u500b\u6574\u6578\u3002

    Python \u7684\u8a9e\u6cd5\u771f\u7684\u5f88\u9748\u6d3b\uff0c\u4f46\u4e5f\u8981\u5f88\u5c0f\u5fc3\uff0c\u4ed6\u63d0\u4f9b\u4e86\u5f88\u591a\u5de5\u5177\uff0c\u4f46\u5982\u679c\u4f60\u4e0d\u6e05\u695a\u4ed6\u662f\u600e\u9ebc\u904b\u4f5c\u7684\uff0c\u5c31\u6703\u5bb9\u6613\u6703\u5beb\u51fa\u6548\u7387\u4f4e\u4e0b\u7684\u7a0b\u5f0f\u78bc\uff0c\u9019\u4e5f\u662f\u96d9\u9762\u5203\uff0c\u6240\u4ee5\u8981\u591a\u591a\u7df4\u7fd2\uff0c\u591a\u591a\u601d\u8003\uff0c\u4f60\u53ef\u4ee5\u7684\u3002

    "},{"location":"fundamental/python/lists/#practice","title":"Practice","text":"

    Itsa - [C_MM33-\u6613] \u627e1~N\u7684\u5b8c\u7f8e\u6578

    Reference code

    table = []\nfor i in range(6, 2 ** 13, 2):\n    s = 0\n    for j in range(1, i):\n        if i % j == 0:\n            s += j\n    if s == i:\n        table.append(i)\n\nwhile True:\n    N = int(input())\n    print(' '.join([str(x) for x in table if x <= N]))\n
    \u5efa\u7acb\u4e00\u500b\u4e32\u5217 table\uff0c\u88e1\u9762\u653e\u4e86 \\(6\\) \u5230 \\(2^{13}\\) \u4e4b\u9593\u7684\u5b8c\u7f8e\u6578\uff0c\u63a5\u8457\u8f38\u5165\u4e00\u500b\u6574\u6578 \\(N\\)\uff0c\u8f38\u51fa \\(1\\) \u5230 \\(N\\) \u4e4b\u9593\u7684\u5b8c\u7f8e\u6578\u3002

    \u90a3\u9ebc \\(2^{13}\\) \u662f\u600e\u9ebc\u4f86\u7684?\u311c\uff0c\u6211\u5237\u5f8c\u53f0\u6e2c\u8cc7\u63a8\u6572\u4f86\u7684\u3002

    join \u65b9\u6cd5\u53ef\u4ee5\u5c07\u5b57\u4e32\u4e32\u5217\u4e2d\u7684\u5143\u7d20\u7528\u6307\u5b9a\u7684\u5b57\u4e32\u9023\u63a5\u8d77\u4f86\uff0c\u9019\u908a\u7528\u7a7a\u767d\u5b57\u4e32 ' ' \u4f86\u9023\u63a5\u3002

    \u9019\u7a2e\u6280\u5de7\u7a31\u70ba\u300c\u5efa\u8868\u300d\uff0c\u4e8b\u5be6\u4e0a\u5b8c\u7f8e\u6578\u5f88\u758f\u6563\uff0c\u4f60\u751a\u81f3\u53ef\u4ee5\u81ea\u5df1\u5efa\u5b8c\u8868\u5f8c\u76f4\u63a5\u5beb\u6b7b\uff0c\u4f46\u9019\u6a23\u7684\u8a71\uff0c\u7a0b\u5f0f\u78bc\u5c31\u4e0d\u5177\u6709\u901a\u7528\u6027\u3002

    table = [6, 28, 496, 8128]\n\nN = int(input())\nprint(' '.join(str(x) for x in table if x <= N))\n

    \u5982\u679c\u5c31\u55ae\u7d14\u89e3\u984c\u7684\u8a71\uff0c\u9019\u6a23\u4e5f\u662f\u53ef\u4ee5\u7684\u3002

    \u6b63\u898f\u7684\u984c\u76ee\u90fd\u6703\u898f\u7bc4\u6e2c\u8cc7\u7bc4\u570d\uff0c\u5982\u679c\u4f60\u4ee5\u5f8c\u4e0a\u5927\u5b78\u5f8c\u9047\u5230\u4e0d\u592a\u9748\u5149\u7684\u52a9\u6559\u6c92\u6709\u6a19\u6e2c\u8cc7\u7bc4\u570d\uff0c\u8a18\u5f97\u96fb\u6b7b\u4ed6\u5011\u3002

    Itsa - [C_MM44-\u6613] The Numbers

    Reference code
    N, M = input().split()\n\ncnt = 0\nfor i in range(0, 6):\n    if M[i] == N[0] and M[i + 1] == N[1]:\n        cnt += 1\n\nprint(cnt)\n

    \u5b57\u4e32\u4e5f\u53ef\u4ee5\u50cf\u662f\u4e32\u5217\u4e00\u6a23\uff0c\u4f7f\u7528\u7d22\u5f15\u503c\u4f86\u5b58\u53d6\u5143\u7d20\u3002

    Itsa - [C_AR01-\u6613] \u4e00\u7dad\u9663\u5217\u53cd\u8f49 I

    Reference code
    arr = input().split()\nprint(' '.join(arr[::-1]))\n

    arr.reverse() \u4e5f\u884c\uff0c\u4f46\u662f\u9019\u6a23\u6703\u6539\u8b8a\u539f\u672c\u7684\u4e32\u5217\uff0c\u5982\u679c\u4f60\u4e0d\u60f3\u6539\u8b8a\u539f\u672c\u7684\u4e32\u5217\uff0c\u5c31\u4f7f\u7528 arr[::-1]\u3002

    arr = input().split()\narr.reverse()\nprint(' '.join(arr))\n

    Itsa - [C_AR03-\u6613] \u8a08\u7b97\u9663\u5217\u4e2d\u6240\u6709\u5143\u7d20\u7684\u7acb\u65b9\u548c

    Reference code
    arr = map(int, input().split())\nans = 0\n\nfor num in arr:\n    ans += num ** 3\n\nprint(ans)\n

    \u6211\u4e26\u6c92\u6709\u628a map \u7269\u4ef6\u8f49\u63db\u6210\u4e32\u5217\uff0c\u56e0\u70ba\u6211\u53ea\u9700\u8981\u4e00\u6b21\u8fed\u4ee3\uff0c\u6240\u4ee5\u76f4\u63a5\u7528 map \u7269\u4ef6\u5c31\u597d\u3002

    \u4f86\u770b\u4e00\u884c\u89e3:

    print(sum(int(x) ** 3 for x in input().split()))\n

    \u53c3\u8003\u5c31\u597d\u3002

    Itsa - [C_AR09-\u6613] \u5169\u6578\u5dee\u503c

    Reference code
    arr1 = list(map(int, input().split(',')))\narr1.sort()\narr2 = arr1.copy()\narr2.sort(reverse=True)\n\nmax_num,min_num  = 0, 0\nfor i in range(len(arr1) - 1, -1, -1):\n    # convert list to number\n    max_num = max_num * 10 + arr1[i]\n    min_num = min_num * 10 + arr2[i]\n\nprint(max_num - min_num)\n

    \u4e0d\u61c2\u6392\u5e8f\u6c92\u95dc\u4fc2\uff0c\u6211\u5011\u5148\u77e5\u9053\u600e\u9ebc\u7528\u5c31\u597d\uff0c\u4ee5\u5f8c\u6211\u6703\u6559\u4f60\u539f\u7406\u3002

    \u800c\u9019\u984c\u7684\u91cd\u9ede\u662f\uff0c\u5982\u4f55\u5c07\u4e32\u5217\u8f49\u63db\u6210\u6578\u5b57\u3002\u5f9e\u500b\u4f4d\u6578\u958b\u59cb\uff0c\u6bcf\u6b21\u4e58 \\(10\\)\uff0c\u518d\u52a0\u4e0a\u4e0b\u4e00\u500b\u6578\u5b57\u3002

    Itsa - [C_AR022-\u6613] \u5b57\u6bcd\u51fa\u73fe\u7684\u983b\u7387

    Reference code
    string = input()\n\nfreq = [0] * 26\n\nfor c in string:\n    if c.isalpha():\n        freq[ord(c.lower()) - ord('a')] += 1\n\nprint(' '.join(str(x) for x in freq))\n

    \u9019\u984c\u9700\u8981\u4e00\u500b\u5148\u5099\u77e5\u8b58\uff0cASCII \u78bc\uff0cord \u51fd\u5f0f\u53ef\u4ee5\u53d6\u5f97\u5b57\u5143\u7684 ASCII \u78bc\u3002

    \u518d\u5229\u7528 isalpha \u65b9\u6cd5\uff0c\u4f86\u5224\u65b7\u5b57\u5143\u662f\u5426\u70ba\u5b57\u6bcd\uff0c\u4ee5\u53ca lower \u65b9\u6cd5\uff0c\u4f86\u5c07\u5b57\u6bcd\u8f49\u63db\u6210\u5c0f\u5beb\uff0c\u9019\u6a23\u5c31\u53ef\u4ee5\u5c07\u5b57\u6bcd\u6620\u5c04\u5230 0 \u5230 25 \u4e4b\u9593\u3002

    \u95dc\u65bc\u5b57\u4e32\u7684\u4e3b\u984c\uff0c\u5f8c\u9762\u6703\u518d\u8ddf\u4f60\u4ecb\u7d39\u3002

    Itsa - [C_AR025-\u6613] \u8a08\u7b97ASCII\u5b57\u5143

    Reference code
    string = input()\n\nfreq = [0] * 128\n\n\nfor i in range(len(string)):\n    freq[ord(string[i])] += 1\n\nfor i in range(len(freq) - 1, -1, -1):\n    if freq[i] > 0:\n        print(f'{i} {freq[i]}')\n

    \u9019\u984c\u8ddf\u4e0a\u4e00\u984c\u5f88\u50cf\u3002

    Itsa - [C_AR029-\u96e3] \u6587\u5b57\u7de8\u78bc

    Reference code
    plain_text = input()\n\nN = len(plain_text)\nM = 1\nwhile M * M < N:\n    M += 1\n\narr = [[' ' for _ in range(M)] for _ in range(M)]\n\nfor i in range(N):\n    arr[i // M][i % M] = plain_text[i]\n\ncipher_text = []\nfor i in range(M):\n    for j in range(M):\n        cipher_text.append(arr[j][i])\n\nprint(''.join(cipher_text))\n

    \u77e9\u9663\u8f49\u7f6e\uff0c\u6240\u4ee5 arr[j][i] \u8b8a\u6210 arr[i][j]\u3002

    "},{"location":"fundamental/python/lists/#assignment","title":"Assignment","text":"

    Itsa - [C_MM42-\u4e2d] \u6c42(-1)^(n+1)x[1/(2n-1)]\u7684\u548c

    Itsa - [C_AR02-\u6613] \u4e00\u7dad\u9663\u5217\u53cd\u8f49 II

    Itsa - [C_AR10-\u4e2d] \u65b0\u901a\u8a71\u8cbb\u7387

    Itsa - [C_AR021-\u6613] \u6210\u7e3e\u7d71\u8a08

    Itsa - [C_AR023-\u6613] \u5b57\u6839\u8207\u5b50\u5b57\u4e32

    Itsa - [C_AR031-\u4e2d] \u4e00\u7dad\u77e9\u9663\u8868\u793a\u4e8c\u7dad\u5e73\u9762\u7a7a\u9593

    Itsa - [C_AR33-\u6613] \u8f49\u7f6e\u77e9\u9663

    Itsa - [C_AR34-\u6613] \u8eab\u5206\u8b49\u9a57\u8b49\u5668

    Itsa - [C_AR35-\u6613] \u751f\u8096\u554f\u984c

    Itsa - [C_AR41-\u6613] \u4e00\u6574\u6578\u5e8f\u5217\u6240\u542b\u4e4b\u6574\u6578\u500b\u6578\u53ca\u5e73\u5747\u503c

    Itsa - [C_AR46-\u6613] \u9663\u5217\u5e73\u65b9\u548c\u554f\u984c

    Itsa - [C_AR48-\u6613] \u6578\u5b57\u52a0\u5bc6

    @EditTime : 2024-02-03 21:30

    "},{"location":"fundamental/python/operators/","title":"Operators","text":""},{"location":"fundamental/python/operators/#introduction","title":"Introduction","text":"

    \u5728\u9019\u500b\u7ae0\u7bc0\u4e2d\uff0c\u6211\u5011\u8981\u4f86\u5b78\u7fd2\u904b\u7b97\u5b50\uff0c\u904b\u7b97\u5b50\u53ef\u4ee5\u8b93\u6211\u5011\u5c0d\u8b8a\u6578\u505a\u904b\u7b97\uff0c\u4f8b\u5982: \u52a0\u6cd5\u3001\u6e1b\u6cd5\u3001\u4e58\u6cd5\u3001\u9664\u6cd5\u7b49\u7b49\u3002

    "},{"location":"fundamental/python/operators/#arithmetic_operators","title":"Arithmetic Operators","text":"

    \u9996\u5148\uff0c\u6211\u5011\u4f86\u770b\u770b\u7b97\u8853\u904b\u7b97\u5b50\uff0c\u6211\u5011\u719f\u6089\u7684\u56db\u5247\u904b\u7b97\u5c31\u662f\u7b97\u8853\u904b\u7b97\u5b50\uff0c\u4ed6\u5011\u5206\u5225\u662f +\u3001-\u3001*\u3001/\uff0c\u5206\u5225\u4ee3\u8868\u52a0\u6cd5\u3001\u6e1b\u6cd5\u3001\u4e58\u6cd5\u3001\u9664\u6cd5\u3002

    x, y = 10, 3\nprint(x + y)\nprint(x - y)\nprint(x * y)\nprint(x / y)\nz = x // y\nprint(z)\nprint(type(z))\nprint(x % y)\nprint(x ** y)\n
    ouput
    13\n7\n30\n3.3333333333333335\n3\n<class 'int'>\n1\n1000\n

    \u6211\u76f8\u4fe1\u770b\u5b8c\u8f38\u51fa\u5f8c\uff0c\u4f60\u80fd\u5927\u81f4\u660e\u77ad\u5404\u500b\u904b\u7b97\u5b50\u7684\u4f5c\u7528\uff0c\u5176\u4e2d\u60f3\u8acb\u4f60\u7559\u610f * \u4e58\u6cd5\u904b\u7b97\u5b50\uff0c\u8acb\u4f60\u4e0d\u8981\u6253\u6210 x\uff0c\u4ee5\u53ca / \u8207 // \u7684\u5dee\u5225\uff0c\u5f8c\u8005\u6703\u5c07\u7d50\u679c\u5411\u4e0b\u53d6\u6574\u3002\u9084\u6709\u6bd4\u8f03\u7279\u5225\u7684 % \uff0c\u7559\u610f\u5230 10 = 3 * 3 + 1\uff0c\u5c31\u662f\u53d6\u9918\u6578\uff1b\u800c\u770b\u8d77\u4f86\u6700\u5947\u7279\u7684 ** \uff0c\u4ed6\u7684\u4f5c\u7528\u662f\u6c42\u51aa\u3002

    \u6211\u5011\u4f86\u8907\u7fd2\u4e00\u4e0b\u570b\u5c0f\u6578\u5b78:

    # Upper case for constant\nPI = 3.14\nr = 2\narea = PI * (r ** 2)\nperimeter = 2 * PI * r\nprint(f'Area: {area}, Perimeter: {perimeter}')\n\n# Sum of 1 to 100\ntotal = (1 + 100) * 100 // 2\nprint(f'The sum of 1 to 100 is {total}')\n

    ouput
    Area: 12.56, Perimeter: 12.56\nThe sum of 1 to 100 is 5050\n

    \u9019\u908a\u8981\u63d0\u9192\u4f60\u7684\u662f\uff0c\u904b\u7b97\u5b50\u4e4b\u9593\u6709\u512a\u5148\u9806\u5e8f\uff0c\u7576\u4f60\u4e0d\u78ba\u5b9a\u7d50\u679c\u7684\u6642\u5019\uff0c\u8acb\u5584\u7528\u62ec\u865f\u3002

    x = 'A' + 'n' + 'i' + 'm' + 'a' + 'l' + 's'\nprint(x)\n
    ouput
    Animals\n

    Martin Garrix - Animals (Official Video)

    \u518d\u8acb\u4f60\u7559\u610f\u4e00\u4ef6\u4e8b\uff0c\u4e0d\u540c\u985e\u5225\u5c0d\u65bc\u904b\u7b97\u5b50\u7684\u4f5c\u7528\u662f\u4e0d\u540c\u7684\uff0c\u4f8b\u5982\u5b57\u4e32\u7684 + \u6703\u5c07\u5169\u500b\u5b57\u4e32\u76f8\u9023\uff0c\u800c\u6574\u6578\u7684 + \u5247\u6703\u5c07\u5169\u500b\u6574\u6578\u76f8\u52a0\u3002

    Question

    1. 2 ** 3 ** 2 \u7684\u7d50\u679c\u662f\u591a\u5c11?
    2. 2 ** (3 ** 2) \u7684\u7d50\u679c\u662f\u591a\u5c11?
    3. (2 ** 3) ** 2 \u7684\u7d50\u679c\u662f\u591a\u5c11?
    "},{"location":"fundamental/python/operators/#comparison_operators","title":"Comparison Operators","text":"

    \u6bd4\u8f03\u904b\u7b97\u5b50\u7684\u7d50\u679c\u6703\u662f True \u6216 False\uff0c\u9019\u500b\u7d50\u679c\u6211\u5011\u7a31\u70ba\u5e03\u6797\u503c\u3002

    \u6211\u5011\u4f86\u4ee5\u76f4\u89d2\u4e09\u89d2\u5f62\u7684\u6027\u8cea\u4f86\u505a\u4e00\u4e9b\u6bd4\u8f03\u904b\u7b97\u5b50\u7684\u7df4\u7fd2\u3002

    a, b, c = 3, 4, 5\n\nprint(a < b)\nprint(a > b)\nprint(a <= b)\nprint(a >= b)\nprint(a ** 2 + b ** 2 == c ** 2)\nprint(a ** 2 + b ** 2 != c ** 2)\nprint((a + b) > c)\n
    ouput
    False\nTrue\nFalse\nTrue\nFalse\nTrue\n

    \u9019\u908a\u8981\u63d0\u9192\u4f60\uff0c == \u662f\u6bd4\u8f03\u904b\u7b97\u5b50\uff0c\u800c = \u662f\u6307\u6d3e\u904b\u7b97\u5b50\uff0c\u4ed6\u5011\u7684\u610f\u601d\u662f\u4e0d\u4e00\u6a23\u7684\u3002

    \u6700\u5f8c\u4f86\u770b\u4e00\u500b\u4f8b\u5b50:

    age = 14\nprint(12 <= age <= 18)\n\nx, y, z = 1, 2, 3\nprint(x < y < z)\nprint(x < y and y < z)\n

    ouput
    True\nTrue\nTrue\n

    \u5728Python\u4e2d\uff0c\u6211\u5011\u53ef\u4ee5\u5c07\u6bd4\u8f03\u904b\u7b97\u5b50\u9023\u63a5\u8d77\u4f86\uff0c\u9019\u6a23\u7684\u5beb\u6cd5\u53ef\u4ee5\u8b93\u6211\u5011\u7684\u7a0b\u5f0f\u78bc\u66f4\u7c21\u6f54\u3002

    Question

    1. print(1 < 2 < 3 < 4 < 5) \u6703\u5370\u51fa\u4ec0\u9ebc?
    2. print(1 < 2 < 3 < 4 > 5) \u6703\u5370\u51fa\u4ec0\u9ebc?
    "},{"location":"fundamental/python/operators/#logical_operators","title":"Logical Operators","text":"

    \u6211\u5011\u7e7c\u7e8c\u5f80\u4e0b\u770b\uff0c\u9019\u908a\u6211\u5011\u8981\u4ecb\u7d39\u908f\u8f2f\u904b\u7b97\u5b50\uff0c\u4ed6\u53ef\u4ee5\u5c07\u591a\u500b\u5e03\u6797\u503c\u7d50\u5408\u6210\u4e00\u500b\u5e03\u6797\u503c\u3002

    has_license = True\nis_drunk = False\nage = 18\n\nprint(f\"Can I drive a car? {has_license and not is_drunk and age >= 18}\")\nprint(not has_license)\nprint(not is_drunk)\nprint(age >= 18 or is_drunk or not has_license)\n
    ouput
    Can I drive a car? True\nFalse\nTrue\nTrue\n

    \u9019\u908a\u8981\u63d0\u9192\u4f60\u7684\u662f\uff0c and \u53ea\u6709\u5728\u6240\u6709\u5e03\u6797\u503c\u90fd\u662f True \u7684\u6642\u5019\uff0c\u7d50\u679c\u624d\u6703\u662f True\uff0c\u800c or \u53ea\u8981\u6709\u4e00\u500b\u5e03\u6797\u503c\u662f True\uff0c\u7d50\u679c\u5c31\u6703\u662f True\u3002

    \u56e0\u6b64\u6709\u6240\u8b02\u7684\u77ed\u8def\u6c42\u503c(Short-circuit Evaluation)\uff0c\u7576 and \u7684\u7b2c\u4e00\u500b\u5e03\u6797\u503c\u662f False\uff0c\u5f8c\u9762\u7684\u5e03\u6797\u503c\u5c31\u4e0d\u6703\u88ab\u8a08\u7b97\uff0c\u56e0\u70ba\u7d50\u679c\u4e00\u5b9a\u662f False\uff1b\u800c or \u7684\u7b2c\u4e00\u500b\u5e03\u6797\u503c\u662f True\uff0c\u5f8c\u9762\u7684\u5e03\u6797\u503c\u5c31\u4e0d\u6703\u88ab\u8a55\u4f30\uff0c\u56e0\u70ba\u7d50\u679c\u4e00\u5b9a\u662f True\u3002

    \u800c not \u662f\u4e00\u5143\u904b\u7b97\u5b50\uff0c\u4ed6\u53ea\u6703\u5c07\u5e03\u6797\u503c\u53cd\u8f49\u3002

    Question

    1. print(not True and False) \u6703\u5370\u51fa\u4ec0\u9ebc?
    2. print(not True or False) \u6703\u5370\u51fa\u4ec0\u9ebc?
    3. print(not True and not False) \u6703\u5370\u51fa\u4ec0\u9ebc?
    4. print(not True or not False) \u6703\u5370\u51fa\u4ec0\u9ebc?
    "},{"location":"fundamental/python/operators/#bitwise_operators","title":"Bitwise Operators","text":"

    \u5728\u9019\u908a\u6211\u5011\u8981\u4ecb\u7d39\u4f4d\u5143\u904b\u7b97\u5b50\uff0c\u4ed6\u662f\u5c0d\u4e8c\u9032\u4f4d\u7684\u904b\u7b97\uff0c\u6211\u5011\u53ef\u4ee5\u7528 bin() \u4f86\u89c0\u5bdf\u4e8c\u9032\u4f4d\u7684\u7d50\u679c\u3002

    a, b = 2, 3\nprint(f\"a={bin(a)}\")\nprint(f\"b={bin(b)}\")\n\nprint(a & b, bin(a & b))\nprint(a | b, bin(a | b))\nprint(a ^ b, bin(a ^ b))\nprint(~a, bin(~a))\n\nprint(a << 1, bin(a << 1))\nprint(a >> 1, bin(a >> 1))\n
    ouput
    a=0b10\nb=0b11\n2 0b10\n3 0b11\n1 0b1\n-3 -0b11\n4 0b100\n1 0b1\n

    & \u662f\u4f4d\u5143\u7684 and\uff0c | \u662f\u4f4d\u5143\u7684 or\uff0c ^ \u662f\u4f4d\u5143\u9593\u7684\u9032\u884c\u4e92\u65a5\u6216\u904b\u7b97\uff0c ~ \u662f\u4f4d\u5143\u7684 not\uff0c << \u662f\u4f4d\u5143\u7684\u5de6\u79fb\uff0c >> \u662f\u4f4d\u5143\u7684\u53f3\u79fb\u3002

    \u5728\u5f80\u4e0b\u4e4b\u524d\uff0c\u8acb\u4f60\u5148\u60f3\u60f3\u6211\u5011\u8a72\u5982\u4f55\u5224\u65b7\u4e00\u500b\u6578\u5b57\u662f\u5947\u6578\u9084\u662f\u5076\u6578\uff0c\u6211\u5011\u53ef\u4ee5\u7528 % \u4f86\u5224\u65b7\uff0c\u4f46\u662f\u6211\u5011\u4e5f\u53ef\u4ee5\u7528\u4f4d\u5143\u904b\u7b97\u4f86\u5224\u65b7\u3002

    a, b = 5678, 4843\nprint(f\"Is a even? {a % 2 == 0}\")\nprint(f\"Is b odd? {b & 1 == 1}\")\n
    ouput
    Is a even? True\nIs b odd? True\n

    Question

    1. \u5982\u4f55\u5224\u65b7\u4e00\u500b\u6578\u5b57\u662f 2 \u7684\u51aa?
    2. \u5982\u4f55\u5f97\u5230\u4e00\u500b\u6578\u5b57\u7684 16 \u500d\uff0c\u4f46\u4e0d\u80fd\u7528 * \u4e58\u6cd5\u904b\u7b97\u5b50?
    "},{"location":"fundamental/python/operators/#assignment_operators","title":"Assignment Operators","text":"

    \u6211\u5011\u5df2\u7d93\u5b78\u6703\u4e86\u4e00\u4e9b\u904b\u7b97\u5b50\uff0c\u73fe\u5728\u6211\u5011\u8981\u4f86\u5b78\u7fd2\u4e00\u4e9b\u6307\u6d3e\u904b\u7b97\u5b50\uff0c\u4ed6\u53ef\u4ee5\u5c07\u904b\u7b97\u7d50\u679c\u6307\u5b9a\u7d66\u8b8a\u6578\u3002

    \u5148\u4f86\u770b\u770b\u4e00\u500b\u7c21\u55ae\u7684\u4f8b\u5b50\uff0c\u6211\u5011\u53ef\u4ee5\u7528 += \u4f86\u5c07\u8b8a\u6578\u52a0\u4e0a\u67d0\u500b\u503c\uff0c\u9019\u500b\u904b\u7b97\u5b50\u53ef\u4ee5\u8b93\u6211\u5011\u7684\u7a0b\u5f0f\u78bc\u66f4\u7c21\u6f54\u3002

    x = 1\nx = x + 2\ny = 1\ny += 2\nprint(x, y)\n
    ouput
    3 3\n

    \u518d\u4f86\u770b\u770b\u5176\u4ed6\u7684\u6307\u6d3e\u904b\u7b97\u5b50\u3002

    x = 1\nx += 2\nprint(x)\nx -= 1\nprint(x)\nx *= 3\nprint(x)\nx //= 2\nprint(x)\nx **= 2\nprint(x)\nx <<= 1\nprint(x)\n
    ouput
    3\n2\n6\n3\n9\n18\n

    \u5c0d\u4e86\uff0c\u8acb\u4f60\u5225\u5fd8\u8a18 = \u4e5f\u662f\u4e00\u500b\u6307\u6d3e\u904b\u7b97\u5b50\u3002

    x = y = z = 1\nprint(x, y, z)\n
    ouput
    1 1 1\n

    \u5e0c\u671b\u9019\u500b\u4f8b\u5b50\u53ef\u4ee5\u8b93\u4f60\u66f4\u719f\u6089\u6307\u6d3e\u904b\u7b97\u5b50\u3002

    Question

    1. \u6709\u6c92\u6709 and= \u9019\u500b\u6307\u6d3e\u904b\u7b97\u5b50?
    2. &= \u9019\u500b\u6307\u6d3e\u904b\u7b97\u5b50\u7684\u4f5c\u7528\u662f\u4ec0\u9ebc?
    "},{"location":"fundamental/python/operators/#bonus_f-string_for_float","title":"Bonus: f-string for float","text":"

    \u70ba\u4e86\u80fd\u8b93\u4f60\u7df4\u7fd2\u4e00\u4e9b\u984c\u76ee\uff0c\u6211\u5148\u5728\u9019\u88e1\u4ecb\u7d39\u5982\u4f55\u5370\u51fa\u6d6e\u9ede\u6578\u5230\u6307\u5b9a\u4f4d\u6578\u3002

    \u5728 Say Hello to Python - Input \u4e2d\uff0c\u6709\u7a0d\u5fae\u63d0\u904e\uff0c\u5982\u679c\u4f60\u5b8c\u5168\u6c92\u5370\u8c61\uff0c\u8acb\u4f60\u56de\u53bb\u8907\u7fd2\u4e00\u4e0b\u3002

    \u7d66\u4f60\u6d6e\u9ede\u6578 x \uff0c\u8acb\u4f60\u5370\u51fa x \u7684\u5e73\u65b9\u6839\u8207\u5e73\u65b9\uff0c\u4e26\u4e14\u53ea\u5370\u51fa\u5c0f\u6578\u9ede\u5f8c\u5169\u4f4d\u3002

    x = 3.1415926\nprint(f\"The square root of {x} is {x ** 0.5:.2f}\")\nprint(f\"The square of {x} is {x ** 2:.2f}\")\n
    ouput
    The square root of 3.1415926 is 1.77\nThe square of 3.1415926 is 9.87\n

    @EditTime : 2024-01-27 11:52

    "},{"location":"fundamental/python/operators/#bonus_map_for_input","title":"Bonus: map for input","text":"

    \u518d\u6b21\u8907\u7fd2 Variable and Input - Mutiple Input \u4e2d\u7684\u4f8b\u5b50\uff0c\u6211\u5011\u53ef\u4ee5\u7528 split() \u4f86\u5c07\u8f38\u5165\u7684\u5b57\u4e32\u5207\u5272\u6210\u591a\u500b\u5b57\u4e32\u3002

    \u4f46\u662f\u5982\u679c\u6211\u5011\u60f3\u8981\u5c07\u9019\u4e9b\u5b57\u4e32\u8f49\u63db\u6210\u6574\u6578\uff0c\u6211\u5011\u53ef\u4ee5\u600e\u9ebc\u505a\u5462?

    a, b, c = input().split()\nprint(int(a) + int(b) + int(c))\n
    input
    1 2 3\n
    ouput
    6\n

    \u96d6\u7136\u9019\u6a23\u5beb\u4e5f\u53ef\u4ee5\uff0c\u4f46\u662f\u5982\u679c\u6211\u5011\u60f3\u8981\u8f38\u5165\u5f88\u591a\u500b\u6578\u5b57\uff0c\u9019\u6a23\u5beb\u5c31\u6703\u5f88\u9ebb\u7169\uff0c\u9019\u6642\u5019\u6211\u5011\u53ef\u4ee5\u7528 map() \u4f86\u5e6b\u52a9\u6211\u5011\u3002

    a, b, c = map(int, input().split())\nprint(a + b + c)\n
    input
    4 5 6\n
    ouput
    15\n

    map(function, iterable) \u6703\u5c07 iterable \u4e2d\u7684\u6bcf\u4e00\u500b\u5143\u7d20\u90fd\u4e1f\u9032 function \u4e2d\uff0c\u5728\u9019\u88e1\u7684 iterable \u662f input().split()\uff0c\u800c function \u662f int\uff0c\u56e0\u6b64 map(int, input().split()) \u6703\u5c07 input().split() \u4e2d\u7684\u6bcf\u4e00\u500b\u5143\u7d20\u90fd\u8f49\u63db\u6210\u6574\u6578\u3002

    \u4f60\u53ef\u4ee5\u5617\u8a66\u5c07\u4f7f\u7528\u5225\u7684\u51fd\u5f0f\uff0c\u4f8b\u5982 float \u6216 str\uff0c\u4f46\u8acb\u4f60\u8a18\u5f97\u4e0d\u8981\u52a0\u4e0a\u62ec\u865f\uff0c\u56e0\u70ba\u6211\u5011\u53ea\u662f\u8981\u5c07\u51fd\u5f0f\u7684\u540d\u7a31\u50b3\u9032\u53bb\uff0c\u800c\u4e0d\u662f\u8981\u57f7\u884c\u51fd\u5f0f\u3002

    \u6211\u5011\u4f7f\u7528 Unpacking \u7684\u65b9\u5f0f\u4f86\u5c07 map() \u7684\u7d50\u679c\u6307\u6d3e\u7d66\u8b8a\u6578\u3002\u6211\u76f8\u4fe1\u4f60\u9084\u8a18\u5f97\u4ec0\u9ebc\u662f Unpacking \u5427?

    \u5982\u679c\u4f60\u4e0d\u592a\u80fd\u7406\u89e3\uff0c\u4e5f\u6c92\u95dc\u4fc2\uff0c\u5148\u5b78\u6703\u600e\u9ebc\u7528\u5c31\u597d\u3002

    "},{"location":"fundamental/python/operators/#practice","title":"Practice","text":"

    \u6709\u4e86\u672c\u7ae0\u7684\u57fa\u790e\u5f8c\uff0c\u5176\u5be6\u5df2\u7d93\u53ef\u4ee5\u505a\u5f88\u591a\u984c\u76ee\u4e86\uff0c\u6211\u5011\u4f86\u505a\u4e00\u4e9b\u7df4\u7fd2\u984c\u5427!

    Itsa - [C_MM01-\u6613] \u8a08\u7b97\u68af\u578b\u9762\u7a4d

    Reference code
    a, b, h = map(int, input().split())\narea = (a + b) * h / 2\nprint(f\"Trapezoid area:{area}\")\n

    Itsa - [C_MM02-\u6613] \u8a08\u7b97\u4e09\u89d2\u5f62\u9762\u7a4d

    Reference code
    a, b = map(int, input().split())\narea = a * b / 2\nprint(area)\n

    Itsa - [C_MM04-\u6613] \u8a08\u7b97\u7e3d\u548c\u3001\u4e58\u7a4d\u3001\u5dee\u3001\u5546\u548c\u9918\u6578

    Reference code
    a, b = map(int, input().split())\n\nprint(f\"{a}+{b}={a + b}\")\nprint(f\"{a}*{b}={a * b}\")\nprint(f\"{a}-{b}={a - b}\")\nprint(f\"{a}/{b}={a // b}...{a % b}\")\n

    Itsa - [C_MM06-\u6613] \u82f1\u54e9\u8f49\u516c\u91cc

    Reference code
    mile = int(input())\nkm = mile * 1.6\nprint(f\"{km:.1f}\")\n
    "},{"location":"fundamental/python/operators/#assignment","title":"Assignment","text":"

    Itsa - [C_MM07-\u6613] \u8a08\u7b97\u5e73\u65b9\u503c\u8207\u7acb\u65b9\u503c

    Itsa - [C_MM08-\u6613] \u8a08\u7b97\u5169\u6578\u548c\u7684\u5e73\u65b9\u503c

    Itsa - [C_MM10-\u6613] \u651d\u6c0f\u6eab\u5ea6\u8f49\u83ef\u5f0f\u6eab\u5ea6

    Itsa - [C_MM11-\u6613] \u8cfc\u7968\u8a08\u7b97

    Itsa - [C_MM12-\u6613] \u76f8\u9047\u6642\u9593\u8a08\u7b97

    Itsa - [C_MM14-\u6613] \u8a08\u7b97\u6642\u9593\u7684\u7d44\u5408

    @EditTime : 2024-01-28 22:03

    "},{"location":"fundamental/python/repetition_structures/","title":"Repetition Structures","text":""},{"location":"fundamental/python/repetition_structures/#introduction","title":"Introduction","text":"

    \u96fb\u8166\u6700\u6703\u505a\u7684\u4e8b\uff0c\u5c31\u662f\u91cd\u8907\u7684\u4e8b\u60c5\uff0c\u6240\u4ee5\u9019\u88e1\u8981\u8ddf\u4f60\u4ecb\u7d39\u8ff4\u5708(Loop)\uff0c\u8ff4\u5708\u53ef\u4ee5\u8b93\u6211\u5011\u91cd\u8907\u57f7\u884c\u4e00\u6bb5\u7a0b\u5f0f\u78bc\uff0c\u800c\u4e0d\u7528\u4e00\u884c\u4e00\u884c\u7684\u5beb\u51fa\u4f86\u3002

    \u5982\u679c\u4f60\u8981\u5370 \\(100\\) \u6b21 Hello World!\uff0c\u4f60\u6703\u600e\u9ebc\u505a\u5462?

    # ...\nprint(\"Hello World!\")\nprint(\"Hello World!\")\nprint(\"Hello World!\")\n

    \u4f60\u6703\u771f\u7684\u5beb \\(100\\) \u884c\u55ce?\u7576\u7136\u4e0d\u6703\uff0c\u4e0d\u7136\u4f60\u6703\u6c23\u6b7b\uff0c\u7136\u5f8c\u628a\u96fb\u8166\u7838\u4e86\u3002

    "},{"location":"fundamental/python/repetition_structures/#for_loop","title":"For Loop","text":"

    \u9996\u5148\uff0c\u6211\u5011\u4f86\u770b\u770b for \u8ff4\u5708\u7684\u7528\u6cd5\u3002\u4e26\u8209\u500b\u7c21\u55ae\u7684\u4f8b\u5b50\uff0c\u5370\u51fa \\(1\\) \u5230 \\(5\\):

    for i in range(1, 6, 1):\n    print(i, end=' ')\n
    ouput
    1 2 3 4 5\n

    Time Loop - Purrple Cat

    range\uff0c\u9019\u500b\u51fd\u5f0f\u53ef\u4ee5\u7522\u751f\u4e00\u500b\u6578\u5217\uff0c\u4e26\u4e14\u53ef\u4ee5\u6307\u5b9a\u8d77\u59cb\u503c\u3001\u7d50\u675f\u503c\u3001\u9593\u9694\u503c\u3002\u9019\u500b\u51fd\u5f0f\u7684\u7528\u6cd5\u5982\u4e0b:

    \u5982\u679c\u53ea\u6709\u4e00\u500b\u53c3\u6578\uff0c\u90a3\u5c31\u662f\u7d50\u675f\u503c\uff0c\u8d77\u59cb\u503c\u9810\u8a2d\u70ba \\(0\\)\uff0c\u9593\u9694\u503c\u9810\u8a2d\u70ba \\(1\\)\u3002

    range(start=0, stop, step=1) \u4e26\u4e14\u6ce8\u610f\uff0cstop \u662f\u4e0d\u5305\u542b\u5728\u6578\u5217\u4e2d\u7684\u3002

    "},{"location":"fundamental/python/repetition_structures/#foreach","title":"Foreach","text":"

    \u8209\u500b\u4f8b\u5b50\uff0c\u6211\u60f3\u628a\u5b57\u4e32 \"Speed_of_Light\" \u4e2d\u7684\u6bcf\u500b\u5b57\u5143\u90fd\u5370\u51fa\u4f86\u3002

    for c in \"Speed_of_Light\":\n    print(c, end=' ')\n

    ouput

    S p e e d _ o f _ L i g h t \n
    DJ OKAWARI feat. \u4e8c\u5bae\u611b \u300cSpeed of Light\u300d

    \u9019\u88e1\u7684\u8ff4\u5708\u66f4\u63a5\u8fd1\u6982\u5ff5\u4e0a\u7684 Foreach\uff0c\u6bcf\u6b21\u8ff4\u5708\u90fd\u6703\u53d6\u51fa\u5b57\u4e32\u4e2d\u7684\u4e00\u500b\u5b57\u5143\uff0c\u4e26\u4e14\u5c07\u4ed6\u653e\u5230 c \u4e2d\uff0c\u9019\u500b\u6982\u5ff5\u8acb\u4f60\u8a18\u8d77\u4f86\u3002

    "},{"location":"fundamental/python/repetition_structures/#break_and_continue","title":"Break and Continue","text":"

    \u518d\u8209\u500b\u4f8b\u5b50\uff0c\u8a08\u7b97 \\(\\sum_{i=1}^n{i}=1+2+\\cdots+n\\)

    n = int(input())\ntotal = 0\n\n# 1 + 2 + ... + n\nfor i in range(n + 1):\n    total += i\n\nprint(total)\n
    input
    100\n
    ouput
    5050\n

    \u63a5\u4e0b\u4f86\uff0c\u8ddf\u4f60\u4ecb\u7d39 break \u8207 continue\uff0c\u9019\u5169\u500b\u95dc\u9375\u5b57\u53ef\u4ee5\u7528\u4f86\u63a7\u5236\u8ff4\u5708\u7684\u57f7\u884c\u3002

    break \u53ef\u4ee5\u7528\u4f86\u5f37\u5236\u8df3\u51fa\u8ff4\u5708\uff0c\u800c continue \u5247\u662f\u5f37\u5236\u8df3\u5230\u4e0b\u4e00\u6b21\u8ff4\u5708\u3002

    for i in range(1, 11):\n    if i == 5:\n        break\n    print(i, end=' ')\n
    ouput
    1 2 3 4\n

    \u53ef\u4ee5\u767c\u73fe\uff0ci == 5 \u7684\u6642\u5019\uff0c\u8ff4\u5708\u5c31\u88ab\u5f37\u5236\u4e2d\u65b7\u4e86\u3002

    for i in range(1, 11):\n    if i == 5:\n        continue\n    print(i, end=' ')\n
    ouput
    1 2 3 4 6 7 8 9 10\n

    \u53ef\u4ee5\u767c\u73fe\uff0c5 \u88ab\u8df3\u904e\u4e86\u3002

    "},{"location":"fundamental/python/repetition_structures/#nested_loop","title":"Nested Loop","text":"

    \u63a5\u8457\u4ecb\u7d39\u5de2\u72c0\u8ff4\u5708(Nested Loop)\uff0c\u4e5f\u5c31\u662f\u8ff4\u5708\u88e1\u9762\u9084\u6709\u8ff4\u5708\u3002\u505a\u500b\u6bd4\u55bb\u7684\u8a71\uff0c\u5982\u679c\u662f\u5169\u5c64\u7684\u8ff4\u5708\uff0c\u5c31\u50cf\u662f\u6642\u91dd\u8207\u5206\u91dd\uff0c\u5167\u5c64\u8ff4\u5708\u6bcf\u8dd1\u4e00\u5708\uff0c\u5916\u5c64\u8ff4\u5708\u624d\u8dd1\u4e00\u683c\u3002

    \u6211\u5011\u4f86\u5370\u4e00\u500b\u76f4\u89d2\u4e09\u89d2\u5f62\u5427\uff0c\u8f38\u5165\u4e00\u500b\u6578\u5b57 \\(n\\)\uff0c\u5370\u51fa \\(n\\) \u5c64\u7684\u76f4\u89d2\u4e09\u89d2\u5f62\uff0c\u5c07\u6700\u9802\u7aef\u7684\u90a3\u4e00\u5c64\u7de8\u865f\u70ba \\(0\\)\uff0c\u6700\u5e95\u7aef\u7684\u90a3\u4e00\u5c64\u7de8\u865f\u70ba \\(n-1\\)\uff0c\u5176\u4e2d\u7b2c \\(i\\) \u5c64\u6709 \\(i+1\\) \u500b\u661f\u661f *\u3002

    n = int(input())\n\nfor i in range(n):\n    for j in range(i + 1):\n        print('*', end='')\n    print()\n

    \u6211\u7a31\u5167\u5c64\u7684\u8ff4\u5708\u53eb\u505a j \u8ff4\u5708\uff0c\u5916\u5c64\u7684\u8ff4\u5708\u53eb\u505a i \u8ff4\u5708\u3002 j \u8ff4\u5708\u63a7\u5236\u6bcf\u4e00\u5c64\u7684\u661f\u661f\u6578\u91cf\uff0c\u800c i \u8ff4\u5708\u5247\u63a7\u5236\u7e3d\u5171\u6709\u5e7e\u5c64\u3002\u6bcf\u4e00\u5c64\u7684\u661f\u661f\u6578\u91cf\u90fd\u662f i + 1\uff0c\u6700\u5f8c\u6703\u63db\u884c\u3002

    input
    5\n
    output
    *\n**\n***\n****\n*****\n

    \u518d\u4f86\u770b\u4e00\u500b\u7d93\u5178\u7684\u4f8b\u5b50\uff0c\u4e5d\u4e5d\u4e58\u6cd5\u8868\u3002

    for i in range(1, 10):\n    for j in range(1, 10):\n        print(f\"{i} * {j} = {i * j}\", end='\\t')\n    print()\n
    output
    1 * 1 = 1   1 * 2 = 2   1 * 3 = 3   1 * 4 = 4   1 * 5 = 5   1 * 6 = 6   1 * 7 = 7   1 * 8 = 8   1 * 9 = 9   \n2 * 1 = 2   2 * 2 = 4   2 * 3 = 6   2 * 4 = 8   2 * 5 = 10  2 * 6 = 12  2 * 7 = 14  2 * 8 = 16  2 * 9 = 18  \n3 * 1 = 3   3 * 2 = 6   3 * 3 = 9   3 * 4 = 12  3 * 5 = 15  3 * 6 = 18  3 * 7 = 21  3 * 8 = 24  3 * 9 = 27  \n4 * 1 = 4   4 * 2 = 8   4 * 3 = 12  4 * 4 = 16  4 * 5 = 20  4 * 6 = 24  4 * 7 = 28  4 * 8 = 32  4 * 9 = 36  \n5 * 1 = 5   5 * 2 = 10  5 * 3 = 15  5 * 4 = 20  5 * 5 = 25  5 * 6 = 30  5 * 7 = 35  5 * 8 = 40  5 * 9 = 45  \n6 * 1 = 6   6 * 2 = 12  6 * 3 = 18  6 * 4 = 24  6 * 5 = 30  6 * 6 = 36  6 * 7 = 42  6 * 8 = 48  6 * 9 = 54  \n7 * 1 = 7   7 * 2 = 14  7 * 3 = 21  7 * 4 = 28  7 * 5 = 35  7 * 6 = 42  7 * 7 = 49  7 * 8 = 56  7 * 9 = 63  \n8 * 1 = 8   8 * 2 = 16  8 * 3 = 24  8 * 4 = 32  8 * 5 = 40  8 * 6 = 48  8 * 7 = 56  8 * 8 = 64  8 * 9 = 72  \n9 * 1 = 9   9 * 2 = 18  9 * 3 = 27  9 * 4 = 36  9 * 5 = 45  9 * 6 = 54  9 * 7 = 63  9 * 8 = 72  9 * 9 = 81  \n

    i \u63a7\u5236\u5217(Row)\uff0cj \u63a7\u5236\u884c(Column)\uff0c\u6bcf\u4e00\u5217\u7684\u6578\u5b57\u90fd\u662f i\uff0c\u6bcf\u4e00\u884c\u7684\u6578\u5b57\u90fd\u662f j\uff0c\u6240\u4ee5 i * j \u5c31\u662f\u76f8\u61c9\u7684\u4e58\u7a4d\u3002

    \u71b1\u8eab\u5b8c\u4e86\uff0c\u4f86\u770b\u4e00\u500b\u7a0d\u5fae\u8907\u96dc\u7684\u4f8b\u5b50\uff0c\u8f38\u5165\u4e00\u500b\u6578\u5b57\uff0c\u5224\u65b7\u4ed6\u662f\u4e0d\u662f\u8cea\u6578\u3002

    \u9019\u500b\u4f8b\u5b50\u6703\u662f\u7b49\u7b49\u66f4\u8907\u96dc\u7684\u4f8b\u5b50\u7684\u57fa\u790e\uff0c\u6240\u4ee5\u8acb\u4ed4\u7d30\u770b\u3002

    n = int(input())\nis_prime = True\n\nfor i in range(2, n):\n    if n % i == 0:\n        is_prime = False\n        break\n\nif is_prime:\n    print(\"Yes\")\nelse:\n    print(\"No\")\n
    input
    17\n4843\n
    ouput
    Yes\nNo\n

    n \u5982\u679c\u53ef\u4ee5\u6574\u9664 1 \u8207\u81ea\u5df1\u4ee5\u5916\u7684\u6578\u5b57\uff0c\u90a3\u5c31\u4e0d\u662f\u8cea\u6578\uff0c\u6211\u5011\u53ef\u4ee5\u7528 break \u4f86\u5f37\u5236\u8df3\u51fa\u8ff4\u5708\uff0c\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u8a08\u7b97\u3002

    \u6211\u5011\u628a\u554f\u984c\u7528\u5f97\u66f4\u8907\u96dc\uff0c\u8f38\u5165\u4e00\u500b\u6578\u5b57 \\(n\\)\uff0c\u8f38\u51fa\u5728 \\([1, n]\\) \u4e4b\u9593\u6700\u5927\u7684\u8cea\u6578\u3002

    \u5728\u9019\u88e1\u4ecb\u7d39\u5982\u4f55\u8b93 range \u5012\u8457\u6578\u56de\u4f86\u3002

    n = int(input())\n\nfor i in range(n, 0, -1):\n    is_prime = True\n    for j in range(2, i):\n        if i % j == 0:\n            is_prime = False\n            break\n\n    if is_prime:\n        print(f\"{i} is the largest prime in [1, {n}]\")\n        break\n
    input
    100\n2\n
    output
    97 is the largest prime in [1, 97]\n2 is the largest prime in [1, 2]\n

    i \u5217\u8209 \\([n, 1]\\) \u7684\u6578\u5b57\uff0c\u800c j \u5217\u8209 \\([2, i-1]\\) \u7684\u6578\u5b57\uff0c\u5982\u679c i \u53ef\u4ee5\u6574\u9664 j\uff0c\u90a3\u5c31\u4e0d\u662f\u8cea\u6578\uff0c\u99ac\u4e0a\u8df3\u51fa\u5167\u5c64 j \u8ff4\u5708\uff0c\u7e7c\u7e8c\u5217\u8209\u4e0b\u4e00\u500b\u6578\u5b57\u3002\u5982\u679c i \u662f\u8cea\u6578\uff0c\u90a3\u5c31\u5370\u51fa\u4f86\uff0c\u4e26\u4e14\u8df3\u51fa\u5916\u5c64 i \u8ff4\u5708\u3002

    \u8acb\u4f60\u4ed4\u7d30\u7aef\u8a73\u9019\u5169\u500b\u4f8b\u5b50\u4e2d\u5f37\u8abf\u7684\u884c\u6578\u3002

    @EditTime : 2024-01-30 16:33

    "},{"location":"fundamental/python/repetition_structures/#while_loop","title":"While loop","text":"

    \u63a5\u8457\u4f86\u4ecb\u7d39 while \u8ff4\u5708\uff0c\u4ed6\u7684\u4f7f\u7528\u5834\u666f\u662f\u7576\u4f60\u4e0d\u77e5\u9053\u8ff4\u5708\u8981\u57f7\u884c\u5e7e\u6b21\u7684\u6642\u5019\uff0c\u5c31\u53ef\u4ee5\u7528 while \u8ff4\u5708\uff0c\u4f46\u662f\u5225\u5beb\u51fa\u7121\u7aae\u8ff4\u5708(Infinite Loop)\u5594\u3002

    \u4f46\u5728\u5f80\u4e0b\u4e4b\u524d\uff0c\u5148\u4f86\u770b\u5982\u4f55\u7528 while \u8ff4\u5708\u4f86\u5370\u51fa \\(1\\) \u5230 \\(5\\)\u3002

    i = 1\nwhile i < 6:\n    print(i, end=\" \")\n    i += 1\n
    ouput
    1 2 3 4 5\n

    \u56de\u9867\u4e00\u4e0b for loop\uff0c\u4f60\u53ef\u4ee5\u767c\u73fe\u908f\u8f2f\u5176\u5be6\u4e00\u6a23\u3002

    \u7576\u689d\u4ef6\u6210\u7acb\u7684\u6642\u5019\uff0c\u5c31\u6703\u57f7\u884c\u8ff4\u5708\uff0c\u76f4\u5230\u689d\u4ef6\u4e0d\u6210\u7acb\u3002

    \u518d\u8209\u4e00\u500b\u4f8b\u5b50\uff0c\u8f38\u5165\u6b63\u6574\u6578 \\(n\\)\uff0c\u8f38\u51fa \\(n!\\)

    n = int(input())\ni = 1\nfact = 1\n\nwhile i <= n:\n    fact *= i\n    i += 1\n\nprint(fact)\n
    input
    5\n1\n
    ouput
    120\n1\n

    \u4f46\u76ee\u524d\u9019\u5169\u500b\u4f8b\u5b50\u7121\u6cd5\u770b\u51fa while \u7684\u9b45\u529b\uff0c\u56e0\u70ba\u4f60\u90fd\u77e5\u9053\u8ff4\u5708\u4ec0\u9ebc\u6642\u5019\u6703\u7d50\u675f\uff0c\u6240\u4ee5\u8ddf\u4f60\u4ecb\u7d39\u4e00\u500b\u7d93\u5178\u554f\u984c:

    \\[ \\text{The} \\ 3n+1 \\ \\text{Problem} \\ aka \\ \\text{Collatz Conjecture} \\]

    \u8003\u62c9\u8332\u731c\u60f3 wikipedia

    \u662f\u6307\u5c0d\u65bc\u6bcf\u4e00\u500b\u6b63\u6574\u6578\uff0c\u5982\u679c\u5b83\u662f\u5947\u6578\uff0c\u5247\u5c0d\u5b83\u4e583\u518d\u52a01\uff0c\u5982\u679c\u5b83\u662f\u5076\u6578\uff0c\u5247\u5c0d\u5b83\u9664\u4ee52\uff0c\u5982\u6b64\u5faa\u74b0\uff0c\u6700\u7d42\u90fd\u80fd\u5920\u5f97\u52301\u3002

    \u90a3\u6211\u5011\u8981\u5beb\u7684\u7a0b\u5f0f\u662f\uff0c\u8f38\u5165\u4e00\u500b\u6b63\u6574\u6578 \\(n\\)\uff0c\u8f38\u51fa\u4ed6\u6703\u5728\u5e7e\u6b65\u5f8c\u8b8a\u6210 \\(1\\)\u3002

    \\[ f(n)=\\begin{cases}\\frac{n}{2}, & \\text{if } n \\text{ is even} \\\\ 3n+1, & \\text{if } n \\text{ is odd}\\end{cases} \\]

    \u4f9d\u7167\u5b9a\u7fa9\uff0c\u6211\u5011\u53ef\u4ee5\u5beb\u51fa\u4ee5\u4e0b\u7a0b\u5f0f\u78bc:

    n = int(input())\nstep = 0\n\nwhile n != 1:\n    print(n, end=\" -> \")\n    if n % 2 == 0:\n        n = n // 2\n    else:\n        n = 3 * n + 1\n    step += 1\n\nprint(1)\nprint(f\"step = {step}\")\n
    input
    22\n1\n
    ouput
    22 -> 11 -> 34 -> 17 -> 52 -> 26 -> 13 -> 40 -> 20 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1\nstep = 15\n1\nstep = 0\n

    \u518d\u4f86\u4ecb\u7d39\u4e00\u500b\u7d93\u5178\u7684\u4f8b\u5b50\uff0c\u8f38\u5165\u4e00\u500b\u6b63\u6574\u6578 \\(n\\gt 1\\)\uff0c\u8f38\u51fa \\(n\\) \u7684\u8cea\u56e0\u6578\u5206\u89e3\u3002

    \u8acb\u4f60\u5148\u81ea\u5df1\u60f3\u4e00\u4e0b\uff0c\u518d\u770b\u770b\u53c3\u8003\u7a0b\u5f0f\u78bc\u3002

    Example
    n = int(input())\nfactor = 2\n\nwhile n != 1:\n    while n % factor == 0:\n        print(factor, end=' ')\n        n //= factor\n    factor += 1\n
    input
    20\n4843\n
    ouput
    2 2 5\n29 167\n

    \u5167\u5c64\u7684 while \u8ff4\u5708\u6703\u4e00\u76f4\u57f7\u884c\uff0c\u76f4\u5230 n \u4e0d\u662f factor \u7684\u500d\u6578\u70ba\u6b62\u3002\u5916\u5c64\u7684 while \u8ff4\u5708\u5247\u662f\u5217\u8209\u6240\u6709\u7684\u8cea\u56e0\u6578\uff0c\u76f4\u5230 n \u8b8a\u6210 \\(1\\) \u70ba\u6b62\u3002

    \u984c\u5916\u8a71\uff0c\u7576\u521d\u9047\u5230\u9019\u500b\u984c\u76ee\u7684\u6642\u5019\uff0c\u60f3\u4e86\u4e00\u4e0b\u7d50\u679c\u4e00\u6b21\u5c31AC\uff0c\u662f\u5f88\u6709\u6210\u5c31\u611f\u7684\u4e00\u4ef6\u4e8b\uff0c\u6240\u4ee5\u4e5f\u8acb\u4f60\u597d\u597d\u52aa\u529b\uff0c\u9010\u6b65\u57f9\u990a\u81ea\u4fe1\uff0c\u4f60\u4e5f\u53ef\u4ee5\u7684\u3002

    @EditTime : 2024-01-30 17:55

    "},{"location":"fundamental/python/repetition_structures/#bonus_for_else_and_while_else","title":"Bonus: for ... else and while ... else","text":"

    for \u8207 while \u8ff4\u5708\u90fd\u53ef\u4ee5\u642d\u914d else \u4f86\u4f7f\u7528\uff0c\u7576\u8ff4\u5708\u6b63\u5e38\u7d50\u675f\u7684\u6642\u5019(\u6c92\u6709 break )\uff0c\u5c31\u6703\u57f7\u884c else\u3002

    \n
    "},{"location":"fundamental/python/repetition_structures/#practice","title":"Practice","text":"

    Itsa - [C_MM03-\u6613] \u5169\u6578\u7e3d\u548c

    Reference code

    while True:\n    a, b = map(int, input().split())\n    print(a + b)\n
    \u9019\u984c\u6703\u51fa\u73fe\u5728\u9019\u88e1\uff0c\u55ae\u7d14\u662f\u56e0\u70ba\u8981\u91cd\u8907\u8f38\u5165\u3002

    Itsa - [C_MM26-\u6613] \u8f38\u51fa 1x1\u30012x2\u3001...\u3001NxN\u4e4b\u7d50\u679c

    Reference code
    N = int(input())\n\nfor i in range(1, N + 1):\n    print(f\"{i}*{i}={i * i}\")\n

    Itsa - [C_MM33-\u6613] \u627e1~N\u7684\u5b8c\u7f8e\u6578

    Reference code

    N = int(input())\n\nfor i in range(6, N + 1, 2):\n    s = 0\n    for j in range(1, i):\n        if i % j == 0:\n            s += j\n    if s == i:\n        if i == 6:\n            print(i, end='')\n        else:\n            print(' ' + str(i), end='')\nprint()\n
    \u9019\u662f\u66b4\u529b\u89e3\uff0c\u6703TLE\uff0c\u4e0b\u4e00\u7ae0\u6703\u4ecb\u7d39\u5982\u4f55\u6700\u4f73\u5316\uff0c \u4f46\u5982\u679c\u4f7f\u7528 C++ \u7684\u8a71\uff0c\u76f8\u540c\u908f\u8f2f\u7684\u7a0b\u5f0f\u78bc\u662f\u53ef\u4ee5AC\u7684\u3002

    Itsa - [C_MM34-\u6613] \u56e0\u6578\u554f\u984c

    Reference code
    N = int(input())\n\nprint(1, end=\"\")\nfor i in range(2, N + 1):\n    if N % i == 0:\n        print(f\" {i}\", end=\"\")\nprint()\n

    @EditTime : 2024-01-30 18:40

    "},{"location":"fundamental/python/repetition_structures/#assignment","title":"Assignment","text":"

    Itsa - [C_MM21-\u6613] \u7b97\u968e\u4e58

    Itsa - [C_MM25-\u6613] \u8a08\u7b97\u6b63\u6574\u6578\u88ab3\u6574\u9664\u4e4b\u6578\u503c\u4e4b\u7e3d\u548c

    Itsa - [C_MM27-\u6613] \u8a08\u7b97\u5169\u6574\u6578\u9593\u6240\u6709\u6574\u6578\u7684\u7e3d\u548c

    Itsa - [C_MM28-\u6613] \u8a08\u7b971\u5230N\u4e4b\u9593\u5c6c\u65bc5\u548c7\u7684\u500d\u6578

    Itsa - [C_MM29-\u6613] \u6700\u5927\u8cea\u6578\u554f\u984c

    Itsa - [C_MM30-\u6613] \u8cea\u6578\u5224\u5225

    Itsa - [C_MM31-\u6613] \u8a08\u7b971~N\u5167\u80fd\u88ab2\u8ddf3\u6574\u9664\uff0c\u4f46\u4e0d\u80fd\u88ab12\u6574\u9664\u7684\u6574\u6578\u7e3d\u548c

    Itsa - [C_MM40-\u6613] 1~N\u4e4b\u9593\u7684\u7e3d\u548c

    Itsa - [C_MM49-\u6613] \u9023\u7e8c1\u7684\u500d\u6578

    Itsa - [C_ST09-\u6613] \u661f\u865f\u77e9\u5f62\u8f38\u51fa

    Itsa - [C_ST14-\u6613] \u6578\u5b57\u76f4\u89d2\u4e09\u89d2\u5f62\u8f38\u51fa

    @EditTime : 2024-01-30 21:51

    "},{"location":"fundamental/python/say_hello/","title":"Say Hello to Python!","text":""},{"location":"fundamental/python/say_hello/#first_program","title":"First Program","text":"

    \u55e8\uff0c\u9019\u662f\u4f60\u7b2c\u4e00\u500b Python \u7a0b\u5f0f\uff0c\u5728 Pycharm \u4e2d\u5efa\u7acb\u4e00\u500b main.py \u6a94\u6848\uff0c\u4e26\u5728\u6a94\u6848\u4e2d\u6253\u4e0a :

    # print(\"Hello Cat!\")\nprint(\"Hello World!\")\nprint('Hello Python!')\nprint(\"cheung4843\")\n

    \u6309\u4e0b\u57f7\u884c\u5f8c\uff0c\u4f60\u7684\u63a7\u5236\u53f0(Console)\u5c07\u6703\u5370\u51fa Hello World! \u63a5\u8457\u63db\u884c\uff0c\u518d\u5370\u51fa Hello Python!\uff0c\u63a5\u8457\u518d\u5370\u51fa\u6211 cheung4843\uff0c\u518d\u63db\u884c\u3002

    \u90a3 # print(\"Hello Cat!\") \u662f\u4ec0\u9ebc?\u4ee5\u4e95\u5b57\u865f\u70ba\u958b\u982d\u7684\uff0c\u88ab\u7a31\u70ba\u8a3b\u89e3\uff0c\u4ed6\u4e0d\u6703\u5728\u7a0b\u5f0f\u4e2d\u88ab\u57f7\u884c\uff0c\u4ed6\u53ef\u4ee5\u5e6b\u52a9\u4f60\u7406\u89e3\u7a0b\u5f0f\u78bc\uff0c\u6216\u8005\u8b93\u4f60\u7684\u7a0b\u5f0f\u78bc\u53ef\u8b80\u6027\u66f4\u4f73\u3002

    \u4e0d\u66c9\u5f97\u4f60\u662f\u5426\u6709\u767c\u73fe \"Hello World!\" \u8207 'Hello Python!' \u7684\u5dee\u7570?\u7576\u7136\u9664\u4e86\u5b57\u6bcd\u4e0d\u4e00\u6a23\u4e4b\u5916\uff0c\u9084\u6709\u96d9\u5f15\u865f\u8207\u55ae\u5f15\u865f\u7684\u5dee\u5225\uff0c\u4f46\u4ed6\u5011\u90fd\u88ab\u7a31\u70ba\u5b57\u4e32(String)\uff0c\u5728 Python \u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u6210\u5c0d\u7684\u96d9\u5f15\u865f\u8207\u55ae\u5f15\u865f\u4f86\u8868\u9054\u4e00\u500b\u5b57\u4e32\uff0c\u4f46\u662f\u4e0d\u80fd\u6df7\u7528\uff0c\u4f8b\u5982 :

    print(\"I love cats')\n

    \u57f7\u884c\u5f8c\uff0c\u4f60\u6703\u767c\u73fe\u63a7\u5236\u53f0\u8ddf\u4f60\u5831\u544a\u4e86\u932f\u8aa4\uff0c\u9019\u662f\u8a9e\u6cd5\u932f\u8aa4\uff0c\u800c\u5f8c\u7e8c\u5beb\u7a0b\u5f0f\u7684\u904e\u7a0b\u4e2d\uff0c\u4f60\u5c07\u906d\u9047\u8a31\u591a\u8a9e\u610f\u932f\u8aa4\u3002

    \u90a3\u4f60\u77e5\u9053\u4ec0\u9ebc\u662f\u7a7a\u5b57\u4e32\u55ce?

    print('')\nprint(\"\")\nprint(\"Above are nothing, right?\")\n

    \u57f7\u884c\u5b8c\u5f8c\uff0c\u4f60\u5c31\u77e5\u9053\u7a7a\u5b57\u4e32\u662f\u4ec0\u9ebc\u4e86\u5427?

    \u63a5\u8457\u6211\u5011\u4f86\u8b1b\u8b1b print \u9019\u500b\u6771\u897f\uff0c\u6211\u5011\u5728 Python \u4e2d\u7a31\u4ed6\u70ba\u51fd\u5f0f(Function)\uff0c\u6211\u5011\u8981\u5982\u4f55\u4f7f\u7528\u5462?\u4e5f\u5c31\u662f\u5728\u51fd\u5f0f\u7684\u540d\u7a31\u5f8c\u52a0\u4e0a\u4e00\u500b\u62ec\u865f()\u3002\u800c print \u662f Python \u5167\u5efa\u7d66\u6211\u5011\u7684\u300c\u5de5\u5177\u300d\uff0c\u5c31\u662f\u8aaa\uff0c\u6211\u5011\u4e0d\u77e5\u9053\u4ed6\u662f\u600e\u9ebc\u88ab\u9020\u51fa\u4f86\u7684\uff0c\u6211\u5011\u73fe\u968e\u6bb5\u53ea\u8981\u77e5\u9053\u600e\u9ebc\u7528\u5c31\u597d\uff0c\u6216\u8a31\u4f60\u53ef\u80fd\u807d\u904e\u4e00\u500b\u8001\u6389\u7259\u7684\u6bd4\u55bb\uff0c\u7a31\u51fd\u5f0f\u5c31\u50cf\u662f\u4e00\u500b\u9ed1\u76d2\u5b50\u3002

    \u95dc\u65bc\u51fd\u5f0f(Function)\uff0c\u6211\u6703\u5728\u5f80\u5f8c\u7684\u7ae0\u7bc0\u8ddf\u4f60\u4ecb\u7d39\uff0c\u800c\u73fe\u5728\u4f60\u53ea\u8981\u77e5\u9053 print() \u6703\u5c07\u62ec\u865f\u5167\u7684\u6771\u897f\u5370\u51fa\u4f86\uff0c\u4e26\u63db\u884c\u3002

    \u90a3\u5982\u679c\u6211\u4e0d\u60f3\u63db\u884c\u5462?

    print(\"You\")\nprint(\"are\")\nprint(\"my\", end=' ')\nprint(\"special\", end='\\n')\nprint(\"1234\", end=\"5\")\nprint(\"---------\")\n
    ouput
    You\nare\nmy special\n12345---------\n

    \u5728\u9019\u500b\u5947\u602a\u7684\u7a0b\u5f0f\u78bc\u4e2d\uff0c\u4f60\u767c\u73fe\u6211\u5728 print \u7684\u62ec\u865f\u4e2d\u591a\u52a0\u4e86\u4e00\u500b end= \u7684\u6771\u897f\uff0c\u8b93 print \u5370\u5b8c\u524d\u9762\u7684\u6771\u897f\u5f8c\uff0c\u518d\u5370\u51fa\u7b49\u65bc\u5f8c\u7684\u6771\u897f\u3002

    You are my special

    \u90a3 \\n \u662f\u4ec0\u9ebc\u6771\u897f?\u4ed6\u662f\u8df3\u812b\u5b57\u5143(Escape Character)\u5bb6\u65cf\u4e2d\u7684\u4e00\u54e1\uff0c\u4f60\u73fe\u5728\u53ea\u8981\u77e5\u9053\u4ed6\u80fd\u5920\u63db\u884c\u3002

    Note

    1. \u96d9\u5f15\u865f/\u55ae\u5f15\u865f\u570d\u4f4f\u7684\u5167\u5bb9\uff0c\u7a31\u70ba\u5b57\u4e32\uff0c\u4f8b\u5982 \"cheung4843\" \u8207 '114514 + 1919810' \uff0c\u4f46\u8a18\u4f4f\u55ae\u96d9\u5f15\u865f\u4e0d\u5f97\u6df7\u7528\u3002
    2. print(x, end=y) \u6703\u5370\u51fa x \uff0c\u518d\u5370\u51fa y\uff0c\u800c y \u9810\u8a2d\u70ba \\n \u4e5f\u5c31\u662f\u63db\u884c\u3002

    @EditTime : 2024-01-25 19:23

    Question

    1. \u90a3\u9ebc \"'\" \u8207 \"\"\" \u662f\u5408\u6cd5\u7684\u5b57\u4e32\u55ce?
    2. print() \u62ec\u865f\u5167\u6c92\u6709\u653e\u6771\u897f\u6703\u5370\u51fa\u4ec0\u9ebc?

    @EditTime : 2024-01-25 19:55

    "},{"location":"fundamental/python/selection_structures/","title":"Selection Structures","text":""},{"location":"fundamental/python/selection_structures/#introduction","title":"Introduction","text":"

    \u5728\u6211\u5011\u4eba\u751f\u4e2d\uff0c\u6211\u5011\u6703\u9762\u81e8\u5f88\u591a\u9078\u64c7\uff0c\u6703\u6839\u64da\u7576\u4e0b\u7684\u60c5\u6cc1\uff0c\u505a\u51fa\u4e0d\u540c\u7684\u6c7a\u5b9a\uff0c\u800c\u7a0b\u5f0f\u4e5f\u662f\u4e00\u6a23\uff0c\u6211\u5011\u53ef\u4ee5\u6839\u64da\u4e0d\u540c\u7684\u60c5\u6cc1\uff0c\u57f7\u884c\u4e0d\u540c\u7684\u7a0b\u5f0f\u78bc\uff0c\u9019\u7a31\u70ba\u9078\u64c7\u7d50\u69cb(Selection Structures)\uff0c\u662f\u6d41\u7a0b\u63a7\u5236\u7684\u4e00\u7a2e\u3002

    \u4f8b\u5982\uff0c\u6211\u6839\u64da\u5b78\u6e2c\u6210\u7e3e\uff0c\u4f86\u6c7a\u5b9a\u8981\u586b\u54ea\u4e9b\u5fd7\u9858\uff0c\u6216\u662f\u6211\u6839\u64da\u5929\u6c23\uff0c\u4f86\u6c7a\u5b9a\u8981\u4e0d\u8981\u5e36\u5098\u3002

    "},{"location":"fundamental/python/selection_structures/#if_elif_else","title":"if ... elif ... else","text":"

    \u5728\u5f80\u4e0b\u4e4b\u524d\uff0c\u8acb\u4f60\u5148\u56de\u60f3 Operators - Comparison Operators \u7684\u5167\u5bb9\uff0c\u6211\u5011\u53ef\u4ee5\u900f\u904e\u6bd4\u8f03\u904b\u7b97\u5b50\u4f86\u5f97\u5230\u4e00\u500b\u5e03\u6797\u503c\uff0c\u800c if \u6703\u6839\u64da True \u6216 False \u4f86\u6c7a\u5b9a\u662f\u5426\u57f7\u884c\u67d0\u6bb5\u7a0b\u5f0f\u78bc\u3002

    \u6211\u5011\u5148\u4f86\u770b\u4e00\u500b\u7c21\u55ae\u7684\u4f8b\u5b50:

    \u8f38\u5165\u4e00\u500b\u6574\u6578\uff0c\u8f38\u51fa\u4ed6\u7684\u7d55\u5c0d\u503c\u3002

    num = int(input(\"Enter a number: \"))\n\n# get the absolute value of the input\nif num < 0:\n    num = -num\n\nprint(num)\n
    input
    -1984\n1984\n
    ouput
    1984\n1984\n

    Ivan Torrent - \"1984\" Lyrics Video

    \u908f\u8f2f\u5f88\u7c21\u55ae\uff0c\u5982\u679c\u8f38\u5165\u7684\u6578\u5b57\u5c0f\u65bc\u96f6\uff0c\u90a3\u9ebc\u5c31\u5c07\u4ed6\u653e\u4e0a\u8ca0\u865f\u3002\u63d0\u9192\u4f60\u4e00\u4e0b\uff0c\u9019\u88e1\u7684 - \u8207 not \u4e00\u6a23\uff0c\u90fd\u662f\u4e00\u5143\u904b\u7b97\u5b50\uff0c

    \u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u6211\u5011\u53ea\u6709\u7528\u5230 if\uff0c\u63a5\u8457\u6211\u5011\u6709\u8acb else \u767b\u5834\u3002

    \u8acb\u770b\u4e0b\u4e00\u500b\u4f8b\u5b50\uff0c\u8f38\u5165\u4e00\u500b\u6574\u6578\uff0c\u5224\u65b7\u4ed6\u662f\u5947\u6578\u9084\u662f\u5076\u6578\u3002

    num = int(input(\"Enter a number: \"))\n\n# odd or even\nif num % 2 == 0:\n    print(\"Even\")\nelse:\n    print(\"Odd\")\n
    input
    1983\n-1982\n
    ouput
    Odd\nEven\n

    Timecop1983 - On the Run

    \u9019\u88e1\u6211\u5011\u7528\u5230\u4e86 else\uff0c\u7576 if \u7684\u689d\u4ef6\u4e0d\u6210\u7acb\u6642\uff0c\u5c31\u6703\u57f7\u884c else \u7684\u5167\u5bb9\u3002

    \u6211\u5011\u518d\u4f86\u770b\u66f4\u8907\u96dc\u7684\u4f8b\u5b50\uff0c\u8f38\u5165\u4f60\u7684\u5206\u6578\uff0c\u8f38\u51fa\u4f60\u7684\u8a55\u50f9\uff0c\u56e0\u70ba\u6709\u5f88\u591a\u7a2e\u8a55\u50f9\uff0c\u6240\u4ee5\u9700\u8981\u7528\u5230 elif\u3002

    \u7576 if \u7684\u689d\u4ef6\u4e0d\u6210\u7acb\u6642\uff0c\u5c31\u6703\u6aa2\u67e5\u4e0b\u9762 elif \u7684\u689d\u4ef6\uff0c\u5982\u679c elif \u7684\u689d\u4ef6\u6210\u7acb\uff0c\u5c31\u6703\u57f7\u884c elif \u7684\u5167\u5bb9\uff0c\u5982\u679c\u76ee\u524d\u7684 elif \u7684\u689d\u4ef6\u4e0d\u6210\u7acb\uff0c\u5c31\u6703\u6aa2\u67e5\u4e0b\u4e00\u500b elif \u7684\u689d\u4ef6\uff0c\u5982\u679c\u6240\u6709\u7684 elif \u7684\u689d\u4ef6\u90fd\u4e0d\u6210\u7acb\uff0c\u5c31\u6703\u57f7\u884c else \u7684\u5167\u5bb9\u3002

    \u9019\u6a23\u8b1b\u6216\u8a31\u6709\u9ede\u7e5e\u53e3\uff0c\u4f60\u53ef\u4ee5\u770b\u770b\u4e0b\u9762\u7684\u7a0b\u5f0f\u78bc\uff0c\u61c9\u8a72\u5c31\u80fd\u7406\u89e3\u4e86\u3002

    score = int(input(\"Enter your score: \"))\n\nif score >= 90:\n    print(\"A\")\n    print(\"Excellent!\")\nelif score >= 80:\n    print(\"B\")\nelif score >= 70:\n    print(\"C\")\nelif score >= 60:\n    print(\"D\")\nelse:\n    print(\"F\")\n
    input
    60\n90\n49\n
    ouput
    D\nA\nExcellent!\nF\n

    \u63a5\u4e0b\u4f86\u7d66\u4f60\u4e00\u500b\u53ef\u80fd\u6703\u7591\u60d1\u7684\u4f8b\u5b50:

    score = int(input(\"Enter your score: \"))\nif score >= 60:\n    print(\"D\")\nelif score >= 70:\n    print(\"C\")\nelif score >= 80:\n    print(\"B\")\nelif score >= 90:\n    print(\"A\")\n    print(\"Excellent!\")\nelse:\n    print(\"F\")\n
    input
    90\n
    ouput
    D\n

    \u4f60\u53ef\u80fd\u6703\u89ba\u5f97\u5947\u602a\uff0c\u70ba\u4ec0\u9ebc\u8f38\u5165 90 \u6703\u5370\u51fa D\uff0c\u800c\u4e0d\u662f A\uff0c\u9019\u662f\u56e0\u70ba if \u7684\u689d\u4ef6\u6210\u7acb\u6642\uff0c\u5c31\u6703\u57f7\u884c if \u7684\u5167\u5bb9\uff0c\u5c31\u4e0d\u6703\u6aa2\u67e5 elif \u7684\u689d\u4ef6\u4e86\u3002

    \u6240\u4ee5\uff0c\u4f60\u5728\u64b0\u5beb\u689d\u4ef6\u5f0f\u7684\u6642\u5019\uff0c\u8981\u6ce8\u610f\u9806\u5e8f\uff0c\u4ee5\u53ca\u78ba\u4fdd\u6bcf\u500b\u689d\u4ef6\u662f\u5426\u662f\u4e92\u65a5\u7684\u3002

    score = int(input(\"Enter your score: \"))\n\nif 70 > score >= 60:\n    print(\"D\")\nelif 80 > score >= 70:\n    print(\"C\")\nelif 90 > score >= 80:\n    print(\"B\")\nelif 100 >= score >= 90:\n    print(\"A\")\n    print(\"Excellent!\")\nelse:\n    print(\"F\")\n
    input
    90\n4843\n55\n
    ouput
    A\nExcellent!\nF\nF\n

    \u9019\u6a23\u5c31\u4e0d\u6703\u6709\u554f\u984c\u4e86\uff0c\u4f46\u662f\uff0c\u7576\u6211\u8f38\u5165\u8d85\u904e 100 \u7684\u5206\u6578\u6642\uff0c\u662f\u6703\u5370\u51fa F \u7684\uff0c\u4f60\u8a72\u600e\u9ebc\u89e3\u6c7a\u5462?

    "},{"location":"fundamental/python/selection_structures/#nested_if","title":"Nested if","text":"

    if \u7684\u5167\u5bb9\u53ef\u4ee5\u662f\u53e6\u4e00\u500b if\uff0c\u9019\u7a2e\u7d50\u69cb\u7a31\u70ba\u5de2\u72c0\u689d\u4ef6\u5f0f(Nested if)\u3002

    \u8209\u4e00\u500b\u4f8b\u5b50\uff0c\u5982\u679c\u4f60\u6709\u4e09\u500b\u6574\u6578 a, b, c \uff0c\u8acb\u4f60\u8f38\u51fa\u6700\u5927\u7684\u90a3\u500b\u6578\u5b57\u3002

    a, b, c = map(int, input().split())\nmax_one = None\n\nif a > b:\n    max_one = a\n    if c > max_one:\n        max_one = c\nelse:\n    max_one = b\n    if c > max_one:\n        max_one = c\n\nprint(max_one)\n
    input
    10 20 30\n12 12 12\n-3 -4 -5\n
    ouput
    30\n12\n-3\n

    \u60f3\u6cd5\u5f88\u7c21\u55ae\uff0c\u5148\u8b93 a, b \u9032\u884c\u6bd4\u8f03\uff0c\u5f97\u5230\u6700\u5927\u7684\u90a3\u500b\u6578\u5b57\uff0c\u518d\u8b93 c \u8207 max_one \u6bd4\u8f03\uff0c\u5f97\u5230\u6700\u5927\u7684\u90a3\u500b\u6578\u5b57\u3002

    \u9019\u88e1\u5077\u5077\u544a\u8a34\u4f60\u4e00\u500b\u795e\u5947\u5999\u5999\u5de5\u5177\uff0cmax()\uff0c\u4ed6\u6703\u627e\u51fa\u62ec\u865f\u5167\u7684\u6771\u897f\u4e2d\u6700\u5927\u7684\u90a3\u500b\u6578\u5b57\u3002

    a, b, c = map(int, input().split())\nprint(max(a, b, c))\n
    input
    114514 1919 810\n
    ouput
    114514\n
    "},{"location":"fundamental/python/selection_structures/#match_case","title":"match ... case","text":"

    \u5728 Python 3.10 \u4e2d\uff0c\u65b0\u589e\u4e86 match ... case \uff0c\u4f46\u907a\u61be\u7684\u662f\u4e00\u4e9b\u53e4\u8001\u7684 Online Judge \u7684 Python \u7248\u672c\u592a\u820a\u4e0d\u80fd\u7528\uff0c\u4f46\u6211\u9084\u662f\u60f3\u4ecb\u7d39\u7d66\u4f60\u3002

    \u6211\u5011\u5148\u4f86\u770b\u4e00\u500b\u5728 if ... elif ... else \u4e2d\u7684\u4f8b\u5b50:

    month = int(input(\"Enter a month (1-12): \"))\n\n# which season?\nif 3 <= month <= 5:\n    print(\"Spring\")\nelif 6 <= month <= 8:\n    print(\"Summer\")\nelif 9 <= month <= 11:\n    print(\"Fall\")\nelif month == 12 or month == 1 or month == 2:\n    print(\"Winter\")\nelse:\n    print(\"Invalid month\")\n
    input
    4\n7\n10\n1\n13\n
    ouput
    Spring\nSummer\nFall\nWinter\nInvalid month\n

    \u518d\u4f86\u770b\u770b match ... case \u7684\u7248\u672c:

    month = int(input(\"Enter a month (1-12): \"))\n\nmatch month:\n    case 3 | 4 | 5:\n        print(\"Spring\")\n    case 6 | 7 | 8:\n        print(\"Summer\")\n    case 9 | 10 | 11:\n        print(\"Autumn\")\n    case 12 | 1 | 2:\n        print(\"Winter\")\n    case _:\n        print(\"Invalid month\")\n
    input
    270\n11\n3\n
    ouput
    Invalid month\nAutumn\nSpring\n

    \u662f\u4e0d\u662f\u5f88\u7c21\u6f54\u5462?\u5982\u679c\u4f60\u6709\u5b78\u904e\u5176\u4ed6\u50cf\u662f C, C++, Java \u7b49\u8a9e\u8a00\uff0c\u4f60\u53ef\u80fd\u770b\u904e switch .. case\uff0c\u4f46\u662f match ... case \u66f4\u5f37\u5927!

    \u95dc\u65bc match ... case \u6211\u5c31\u4ecb\u7d39\u5230\u9019\u88e1\uff0c\u66f4\u91cd\u8981\u7684\u662f\uff0c\u4f60\u8981\u77e5\u9053 if ... elif ... else \u7684\u7528\u6cd5\u3002

    @EditTime : 2024-01-29 12:32

    "},{"location":"fundamental/python/selection_structures/#practice","title":"Practice","text":"

    Itsa - [C_MM09-\u6613] \u8a08\u7b97 i \u6b21\u65b9\u7684\u503c

    Reference code
    i = int(input())\nif i > 31:\n    print(\"Value of more than 31\")\nelse:\n    print(1 << i)\n

    Itsa - [C_MM13-\u6613] \u505c\u8eca\u8cbb\u8a08\u7b97

    Reference code
    h1, m1 = map(int, input().split())\nh2, m2 = map(int, input().split())\n\npaid = 0\nminutes = (h2 - h1) * 60 + (m2 - m1)\nif minutes > 240:\n    paid += ((minutes - 240) // 30) * 60\n    minutes = 240\nif minutes > 120:\n    paid += ((minutes - 120) // 30) * 40\n    minutes = 120\npaid += (minutes // 30) * 30\n\nprint(paid)\n

    Itsa - [C_MM15-\u6613] \u5224\u65b7\u5ea7\u6a19\u662f\u5426\u5728\u6b63\u65b9\u5f62\u7684\u7bc4\u570d\u5167

    Reference code
    x, y = map(int, input().split())\n\nif 0 <= x <= 100 and 0 <= y <= 100:\n    print(\"inside\")\nelse:\n    print(\"outside\")\n
    "},{"location":"fundamental/python/selection_structures/#assignment","title":"Assignment","text":"

    Itsa - [C_MM16-\u6613] \u5224\u65b7\u5ea7\u6a19\u662f\u5426\u5728\u5713\u5f62\u7684\u7bc4\u570d\u5167

    Itsa - [C_MM19-\u6613] \u96fb\u8a71\u8cbb\u8a08\u7b97

    Itsa - [C_MM24-\u6613] \u8a08\u7b97\u85aa\u6c34

    Itsa - [C_MM32-\u6613] Armstrong\u6578

    Itsa - [C_MM35-\u6613] \u5e73\u3001\u958f\u5e74\u5224\u5b9a

    Itsa - [C_MM36-\u6613] \u5b63\u7bc0\u5224\u5b9a

    Itsa - [C_MM37-\u6613] \u5224\u65b7\u5ea7\u6a19\u4f4d\u65bc\u4f55\u8655

    Itsa - [C_MM38-\u6613] \u5224\u65b73\u6574\u6578\u662f\u5426\u80fd\u69cb\u6210\u4e09\u89d2\u5f62\u4e4b\u4e09\u908a\u9577

    Itsa - [C_MM39-\u6613] \u5224\u65b7\u662f\u4f55\u7a2e\u4e09\u89d2\u5f62

    Itsa - [C_MM46-\u6613] \u8907\u6578\u904b\u7b97

    Itsa - [C_AR36-\u6613] \u661f\u5ea7\u67e5\u8a62

    @EditTime : 2024-01-29 14:38

    "},{"location":"fundamental/python/sets/","title":"Sets","text":""},{"location":"fundamental/python/sets/#introduction","title":"Introduction","text":""},{"location":"fundamental/python/tuples/","title":"Tuples","text":""},{"location":"fundamental/python/tuples/#introduction","title":"Introduction","text":"

    \u6709\u4e86\u4e0a\u4e00\u7ae0\u7684\u57fa\u790e\u5f8c\uff0c\u6211\u76f8\u4fe1\u5e8f\u5c0d(Tuple)\u5c0d\u4f60\u4f86\u8aaa\u4e0d\u6703\u56f0\u96e3\uff0c\u56e0\u70ba\u5b83\u8ddf\u4e32\u5217(List)\u5f88\u50cf\uff0c\u53ea\u662f\u5b83\u662f\u7528\u5c0f\u62ec\u865f()\u4f86\u8868\u793a\uff0c\u800c\u4e14\u5b83\u662f\u4e0d\u53ef\u8b8a\u7684(immutable)\u3002\u9019\u8868\u793a\u4f60\u4e0d\u80fd\u65b0\u589e\u3001\u522a\u9664\u6216\u4fee\u6539\u88e1\u9762\u7684\u5143\u7d20\u3002\u90a3\u65e2\u7136\u5982\u6b64\uff0c\u70ba\u4ec0\u9ebc\u9084\u8981\u7528\u5b83\u5462?

    "},{"location":"fundamental/python/tuples/#create_a_tuple","title":"Create a Tuple","text":"

    \u8981\u5efa\u7acb\u4e00\u500b\u5e8f\u5c0d\u6709\u5f88\u591a\u7a2e\u65b9\u6cd5\uff0c\u6700\u7c21\u55ae\u7684\u5c31\u662f\u7528\u5c0f\u62ec\u865f()\u628a\u5143\u7d20\u5305\u8d77\u4f86\uff0c\u7528\u9017\u865f,\u9694\u958b\u5c31\u597d\u4e86\u3002

    \u4f46\u5728\u4e0b\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u4f60\u6703\u767c\u73fe\uff0c\u53ea\u6709\u4e00\u500b\u5143\u7d20\u6642\uff0c\u4f60\u5fc5\u9808\u5728\u5f8c\u9762\u52a0\u4e0a\u9017\u865f\u3002\u9019\u908a\u4f60\u81ea\u5df1\u8a66\u8a66\u770b\uff0c\u61c9\u8a72\u90fd\u80fd\u7406\u89e3\u3002

    empty = ()\none = (1,)\ntwo = (1, 2)\nprint(len(empty), len(one), len(two))\nprint(type(empty))\n\nodd = 1, 3, 5\nprint(odd)\nprint(type(odd))\n
    Output
    0 1 2\n<class 'tuple'>\n(1, 3, 5)\n(1, 3, 5)\n<class 'tuple'>\n

    \u4f60\u4e5f\u53ef\u4ee5\u7528tuple()\u4f86\u5efa\u7acb\u4e00\u500b\u5e8f\u5c0d\uff0c\u76f4\u63a5\u770b\u4f8b\u5b50:

    lst = [1, 2, 3, 4, 5]\ntup = tuple(lst)\nprint(tup)\n\ns = \"know me...\"\ns_tup = tuple(s)\nprint(s_tup)\n
    Output
    (1, 2, 3, 4, 5)\n('k', 'n', 'o', 'w', ' ', 'm', 'e', '.', '.', '.')\n

    \u516b\u6728\u6d77\u8389 \u300eknow me...\u300f

    \u9084\u8a18\u5f97 List Comprehension \u55ce?\u6211\u5011\u5c07\u4e2d\u62ec\u865f\u6539\u6210\u5c0f\u62ec\u865f\u8a66\u8a66\u770b:

    gen = (x ** 2 for x in range(5))\nprint(type(gen))\ntup = tuple(gen)\nprint(tup)\n
    Output
    <class 'generator'>\n(0, 1, 4, 9, 16)\n

    \u4f60\u6703\u767c\u73fe\uff0c\u7d50\u679c\u4e26\u975e\u662f\u4f60\u9810\u671f\u7684\u5e8f\u5c0d\uff0c\u800c\u662f\u7522\u751f\u5668(Generator)\uff0c\u4f60\u9084\u9700\u8981\u4f7f\u7528tuple()\u4f86\u8f49\u63db\u3002

    \u81f3\u65bc\u70ba\u4ec0\u9ebc\u8981\u7528\u7522\u751f\u5668(Generator)\uff0c\u6211\u6703\u5728\u672a\u4f86\u7684\u7ae0\u7bc0\u8ddf\u4f60\u8aaa\u660e\uff0c\u53c8\u6316\u5751\u4e86\u3002

    \u90a3\u9ebc\u52a0\u6cd5\u8ddf\u4e58\u6cd5\u5462?\u8ddf\u4e32\u5217(List)\u4e00\u6a23\uff0c\u4f60\u53ef\u4ee5\u7528\u52a0\u6cd5\u4f86\u5408\u4f75\u5169\u500b\u5e8f\u5c0d\uff0c\u7528\u4e58\u6cd5\u4f86\u8907\u88fd\u5e8f\u5c0d\u3002

    a = (1, 2, 3)\nb = 4, 5, 6\nc = a + b\nprint(c)\n\nd = a * 2 + b\nprint(d)\n
    Output
    (1, 2, 3, 4, 5, 6)\n(1, 2, 3, 1, 2, 3, 4, 5, 6)\n
    "},{"location":"fundamental/python/tuples/#operations","title":"Operations","text":""},{"location":"fundamental/python/tuples/#accessing_elements","title":"Accessing elements","text":"

    \u8ddf\u4e32\u5217(List)\u4e00\u6a23\uff0c\u4f60\u53ef\u4ee5\u7528\u7d22\u5f15\u4f86\u5b58\u53d6\u5e8f\u5c0d\u4e2d\u7684\u5143\u7d20\uff0c\u4e5f\u53ef\u4ee5\u7528\u8ca0\u7d22\u5f15\u4f86\u5f9e\u5f8c\u5b58\u53d6\u3002

    t = (1, 2, 3, 4, 5)\nprint(t[0], t[-1])\n
    Output
    1 5\n
    "},{"location":"fundamental/python/tuples/#slicing","title":"Slicing","text":"

    \u540c\u6a23\u7684\uff0c\u4f60\u4e5f\u53ef\u4ee5\u7528\u5207\u7247\u4f86\u53d6\u5f97\u5e8f\u5c0d\u4e2d\u7684\u5b50\u5e8f\u5c0d\u3002

    t = (1, 2, 3, 4, 5)\nprint(t[1:3])\nprint(t[:3])\nprint(t[3:])\nprint(t[:])\n
    Output
    (2, 3)\n(1, 2, 3)\n(4, 5)\n(1, 2, 3, 4, 5)\n
    "},{"location":"fundamental/python/tuples/#modifying_elements","title":"Modifying elements","text":"

    \u4f46\u662f\u4f60\u4e0d\u80fd\u4fee\u6539\u5e8f\u5c0d\u4e2d\u7684\u5143\u7d20\uff0c\u9019\u662f\u4e0d\u53ef\u8b8a\u7684(immutable)\uff0c\u662f\u6709\u6298\u8877\u7684\u65b9\u6cd5\u5566\uff0c\u5c31\u662f\u628a\u5e8f\u5c0d\u8f49\u63db\u6210\u4e32\u5217\uff0c\u518d\u8f49\u63db\u56de\u4f86\u3002

    cat_tup = (\"\ud83d\ude38\", \"\ud83d\ude3a\", \"\ud83d\ude3b\", [\"\ud83d\ude3f\", \"\ud83d\ude40\"])\n\ncat_lst = list(cat_tup)\ncat_lst[1] = \"\ud83d\ude3c\"\ncat_tup = tuple(cat_lst)\nprint(cat_tup)\n\ncat_tup[3][0] = \"\ud83d\ude3e\"\nprint(cat_tup)\n\ncat_tup[1] = \"\ud83d\ude3d\"\nprint(cat_tup)\n
    Output
    ('\ud83d\ude38', '\ud83d\ude3c', '\ud83d\ude3b', ['\ud83d\ude3f', '\ud83d\ude40'])\n('\ud83d\ude38', '\ud83d\ude3c', '\ud83d\ude3b', ['\ud83d\ude3e', '\ud83d\ude40'])\nTypeError: 'tuple' object does not support item assignment\n

    \u4f46\u4f60\u6709\u6c92\u6709\u89ba\u5f97\u602a\u602a\u7684\uff0c\u70ba\u4ec0\u9ebc\u6211\u53ef\u4ee5\u4fee\u6539\u5e8f\u5c0d\u4e2d\u7684\u4e32\u5217\u5462?

    "},{"location":"fundamental/python/tuples/#checking_elements","title":"Checking elements","text":"

    \u4f60\u53ef\u4ee5\u7528 in \u4f86\u6aa2\u67e5\u5143\u7d20\u662f\u5426\u5728\u5e8f\u5c0d\u4e2d\uff0c\u9019\u8ddf\u4e32\u5217\u662f\u4e00\u6a23\u7684\u3002

    fib = (0, 1, 1, 2, 3, 5, 8)\nprint(0 not in fib)\nprint(5 in fib)\n
    Output
    False\nTrue\n

    Question

    \u5c0d\u65bc\u9577\u5ea6\u70ba \\(n\\) \u7684\u7121\u5e8f\u5e8f\u5c0d\uff0c\u8981\u6aa2\u67e5\u67d0\u500b\u5143\u7d20\u662f\u5426\u5b58\u5728\u65bc\u5e8f\u5c0d\u4e2d\uff0c\u6700\u597d\u7684\u60c5\u6cc1\u4e0b\uff0c\u9700\u8981\u6aa2\u67e5\u591a\u5c11\u6b21?

    \u53c8\u662f\u719f\u6089\u7684\u554f\u984c\uff0c\u4f60\u53ef\u4ee5\u7684\u3002

    "},{"location":"fundamental/python/tuples/#methods","title":"Methods","text":"

    \u56e0\u70ba\u5e8f\u5c0d\u662f\u4e0d\u53ef\u8b8a\u7684(immutable)\uff0c\u6240\u4ee5\u53ea\u6709\u5169\u500b\u65b9\u6cd5\uff0c\u4e00\u500b\u662fcount()\uff0c\u4e00\u500b\u662findex()\uff0c\u4f60\u53ef\u4ee5\u81ea\u5df1\u8a66\u8a66\u770b\u3002

    "},{"location":"fundamental/python/tuples/#count","title":"count","text":"

    count() \u6703\u56de\u50b3\u62ec\u865f\u5167\u7684\u5143\u7d20\u5728\u5e8f\u5c0d\u4e2d\u51fa\u73fe\u7684\u6b21\u6578\uff0c\u7576\u7136 List \u4e5f\u6709\u9019\u500b\u65b9\u6cd5\uff0c\u4f46\u524d\u9762\u6211\u4e26\u6c92\u6709\u63d0\uff0c\u56e0\u70ba\u53ef\u4ee5\u653e\u5728\u9019\u88e1\u6c34\u5167\u5bb9(X

    t = ((1, 2), (3, 4), 6, 6, [7, 8])\nprint(t.count(1))\nprint(t.count([7, 8]))\nprint(t.count(6))\n
    Output
    0\n1\n2\n
    "},{"location":"fundamental/python/tuples/#index","title":"index","text":"

    index() \u6703\u56de\u50b3\u62ec\u865f\u5167\u7684\u5143\u7d20\u5728\u5e8f\u5c0d\u4e2d\u7684\u7d22\u5f15\uff0c\u4e00\u6a23\u7684\uff0cList \u4e5f\u6709\u9019\u500b\u65b9\u6cd5\u3002

    t = (\"Love Me Again\", \"John Newman\", 2013)\nprint(t.index(\"John Newman\"))\nprint(t.index(2014))\n
    Output
    1\nValueError: tuple.index(x): x not in tuple\n

    John Newman - Love Me Again

    "},{"location":"fundamental/python/tuples/#tuple_vs_list","title":"Tuple vs List","text":"
    • List
      • \u7528\u4e2d\u62ec\u865f[]\u8868\u793a
      • \u53ef\u8b8a\u7684(mutable)
      • \u4e0d\u53ef\u96dc\u6e4a(unhashable)
      • \u6548\u80fd\u8f03\u5dee
      • \u9069\u7528\u65bc\u983b\u7e41\u7684\u589e\u522a\u6539
    • Tuple
      • \u7528\u5c0f\u62ec\u865f()\u8868\u793a
      • \u4e0d\u53ef\u8b8a\u7684(immutable)
      • \u53ef\u96dc\u6e4a(hashable)
      • \u6548\u80fd\u8f03\u597d
      • \u9069\u7528\u65bc\u4e0d\u9700\u8981\u8b8a\u52d5\u7684\u8cc7\u6599\uff0c\u4f8b\u5982\u5e38\u6578\u3001\u5ea7\u6a19

    \u95dc\u65bc\u300c\u53ef\u96dc\u6e4a\u7684(hashable)\u300d\uff0c\u6211\u6703\u5728\u5b57\u5178(Dict)\u9019\u7ae0\u4e2d\u8ddf\u4f60\u8aaa\u660e\u3002

    "},{"location":"fundamental/python/tuples/#practice","title":"Practice","text":"

    Itsa - [C_AR04-\u6613] \u908a\u7de3\u5075\u6e2c

    Reference code

    N = int(input())\n\ndirs = ((0, 1), (0, -1), (1, 0), (-1, 0))\n\nfor k in range(N):\n    n, m = map(int, input().split())\n    pic = []\n    for _ in range(n):\n        pic.append(input().split())\n\n    for i in range(n):\n        for j in range(m):\n            if pic[i][j] == '0':\n                print('_ ', end='')\n            else:\n                is_edge = False\n                for d in dirs:\n                    x, y = i + d[0], j + d[1]\n                    if 0 <= x < n and 0 <= y < m and pic[x][y] == '0':\n                        is_edge = True\n                        break\n                if is_edge:\n                    print('0 ', end='')\n                else:\n                    print('_ ', end='')\n        print()\n\n    if k != N - 1:\n        print()\n
    \u65b9\u5411 dirs \u5c31\u5f88\u9069\u7528\u5e8f\u5c0d\u4f86\u8868\u793a\uff0c\u56e0\u70ba\u5b83\u662f\u56fa\u5b9a\u7684\uff0c\u4e0d\u6703\u8b8a\u52d5\u3002

    \u672a\u4f86\u5728\u5b78\u5716\u5f62\u8d70\u8a2a\u7684\u6642\u5019\uff0c\u4f60\u6703\u4e00\u76f4\u770b\u5230\u9019\u7a2e\u5beb\u6cd5\u3002

    \u5c0d\u4e86\uff0c \u8ff4\u5708\u8b8a\u6578 _ \u88ab\u7a31\u70ba\u6368\u68c4\u8b8a\u6578\uff0c\u8868\u793a\u4e0d\u9700\u8981\u7528\u5230\u9019\u500b\u8b8a\u6578\uff0c\u53ea\u662f\u70ba\u4e86\u914d\u5408\u8ff4\u5708\u8a9e\u6cd5\u800c\u5df2\u3002

    "},{"location":"fundamental/python/tuples/#assignment","title":"Assignment","text":"

    Itsa - [C_AR119-\u6613] \u5730\u96f7\u5371\u96aa\u6307\u6578\u8868

    Itsa - [C_AR139-\u6613] \u9ec3\u91d1\u63a2\u6e2c

    Itsa - [C-AR140-\u6613] \u6c42\u6700\u5927\u7ce7\u98df\u7522\u91cf

    @EditTime : 2024-02-04 21:15

    "},{"location":"fundamental/python/variable_and_input/","title":"Variable and Input","text":""},{"location":"fundamental/python/variable_and_input/#variable","title":"Variable","text":"

    \u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u4f86\u770b\u600e\u9ebc\u4f7f\u7528\u8b8a\u6578\uff0c\u4ee5\u53ca\u8f38\u5165\u81ea\u5df1\u60f3\u8981\u7684\u6771\u897f\u3002

    x = 4843\nprint(x)\n\nx = \"Memory Reboot\"\nprint(x)\n\nx = '4843'\nprint(x)\n

    \u6216\u8a31\u4f60\u53ef\u80fd\u6703\u89ba\u5f97\u795e\u5947\uff0c\u70ba\u4ec0\u9ebc x \u53ef\u4ee5\u8b8a\u6210\u6578\u5b57\uff0c\u53c8\u53ef\u4ee5\u8b8a\u6210\u5b57\u4e32\uff0c\u9084\u6709\u70ba\u4ec0\u9ebc\u7b2c\u4e00\u500b\u8207\u7b2c\u4e09\u500b\u7684\u8f38\u51fa\u6703\u662f\u76f8\u540c\u7684\u3002

    \u518d\u4f86\u7528\u4e00\u4e9b old-school \u7684\u6bd4\u55bb\uff0c\u4f60\u53ef\u4ee5\u5c07 x \u60f3\u50cf\u6210\u4e00\u500b\u7bb1\u5b50\uff0c\u800c\u7b49\u865f\u53f3\u908a\u7684\u300c\u503c\u300d\u5c31\u662f\u7bb1\u5b50\u88e1\u88dd\u7684\u6771\u897f\u3002\u65e2\u7136\u7bb1\u5b50\u88e1\u9762\u7684\u6771\u897f\u53ef\u4ee5\u8b8a\uff0c\u90a3\u6211\u662f\u4e0d\u662f\u53ef\u4ee5\u8aaa x \u662f\u4e00\u500b\u8b8a\u6578\u5462?

    \u4f46\u8acb\u4f60\u5148\u5fd8\u6389\u9019\u500b\u6bd4\u55bb\uff0c\u56e0\u70ba\u9019\u500b\u6bd4\u55bb\u4e26\u4e0d\u5b8c\u7f8e\uff0c\u4f46\u6211\u60f3\u4f60\u61c9\u8a72\u80fd\u5920\u7406\u89e3\uff0cx \u662f\u4e00\u500b\u8b8a\u6578\uff0c\u800c = \u662f\u6307\u6d3e\u904b\u7b97\u5b50(Assignment Operator)\uff0c\u4ed6\u6703\u5c07\u7b49\u865f\u53f3\u908a\u7684\u6771\u897f\u6307\u6d3e\u7d66\u7b49\u865f\u5de6\u908a\u7684\u8b8a\u6578\uff0c\u6216\u8005\u8aaa x \u6703\u6307\u5411\u7b49\u865f\u53f3\u908a\u7684\u7269\u4ef6(Object)\u3002

    Quote

    \u5728Python\u4e2d\uff0c\u4e00\u5207\u90fd\u662f\u7269\u4ef6\u3002

    \u8acb\u89c0\u770b\u4e0b\u9762\u7684\u52d5\u756b\u3002

    V\u00d8J, Narvent - Memory Reboot (4K Music Video)

    \u518d\u4f86\u4ecb\u7d39\u5e7e\u7a2e\u4e0d\u540c\u7684\u8b8a\u6578\u985e\u578b\u3002

    a = 114514\nprint(type(a))\nb = 1919810.0\nprint(type(b))\nc = 10e3\nprint(type(c))\nd = \"cheung4843\"\nprint(type(d))\ne = True\nprint(type(e))\nf = False\nprint(type(f))\nh = None\nprint(type(h))\n
    type \u544a\u8a34\u4f60\u62ec\u865f\u4e2d\u7684\u6771\u897f\u662f\u4ec0\u9ebc\u985e\u5225(Class)\u3002

    b \u8207 c \u90fd\u662f\u6d6e\u9ede\u6578(Float)\uff0c\u4e5f\u5c31\u662f\u5c0f\u6578\u9ede\u7684\u6578\u5b57\uff0c\u800c d \u5247\u662f\u5b57\u4e32\uff0ce \u8207 f \u5247\u662f\u5e03\u6797(Boolean)\uff0c\u800c h \u5247\u662f\u7a7a\u503c\u3002

    Note

    1. type(x) \u56de\u50b3 x \u7684\u985e\u5225\u3002
    2. int \u6574\u6578\u3002
    3. float \u6d6e\u9ede\u6578\u3002
    4. str \u5b57\u4e32\u3002
    5. bool \u5e03\u6797\u3002
    6. None \u7a7a\u503c\u3002

    Question

    1. print(type(3 + 4.0)) \u6703\u5370\u51fa\u4ec0\u9ebc?
    2. print(type(3 + True)) \u6703\u5370\u51fa\u4ec0\u9ebc?

    @EditTime : 2024-01-27 16:44

    "},{"location":"fundamental/python/variable_and_input/#input","title":"Input","text":"

    \u4f46\u662f\u5982\u679c\u6bcf\u6b21\u60f3\u8981\u4fee\u6539 x \u88e1\u9762\u7684\u6771\u897f\uff0c\u96e3\u9053\u90fd\u8981\u5728\u7a0b\u5f0f\u78bc\u4e2d\u4fee\u6539\u55ce?\u80fd\u4e0d\u80fd\u6211\u81ea\u5df1\u4f86\u8f38\u5165\u5462?

    x = input(\"Enter a number: \")\nprint(type(x))\ny = input(\"Enter another number: \")\nz = int(x) + int(y)\nprint(\"The sum is: \", z)\n

    \u5594\u5e79\uff0c\u600e\u9ebc\u4e00\u4e0b\u5b50\u591a\u51fa\u90a3\u9ebc\u591a\u6771\u897f\uff0c\u5225\u614c\uff0c\u6211\u4f86\u89e3\u91cb\uff0c\u4f46\u8acb\u4f60\u5148\u56de\u60f3\u5728\u524d\u4e00\u7bc0\u4e2d\u5b78\u904e\u7684\u6771\u897f\uff0c\u4f60\u53ef\u4ee5\u767c\u73fe input, int, \u90fd\u662f\u51fd\u5f0f\u3002\u800c input \u62ec\u865f\u4e2d\u7684\u5b57\u4e32\u6703\u986f\u793a\u5728\u63a7\u5236\u53f0\u4e2d\u63d0\u793a\u4f60\u8981\u8f38\u5165\u4ec0\u9ebc\uff0cint \u5247\u662f\u628a\u62ec\u865f\u4e2d\u7684\u6771\u897f\u7684\u985e\u5225\u8f49\u63db\u6210\u6574\u6578\u3002

    \u90a3\u70ba\u4ec0\u9ebc\u5370\u51fatype(x) \u5f97\u5230 <class 'str'> \u5462?\u4ee3\u8868 x \u662f\u4e00\u500b\u5b57\u4e32\uff0c\u9019\u662f\u56e0\u70ba input \u7e3d\u662f\u5c07\u4f60\u8f38\u5165\u9032\u4f86\u7684\u6771\u897f\u7576\u6210\u5b57\u4e32\uff0c\u4f46\u6211\u60f3\u8981\u8b93 z = x + y \u9019\u500b\u6578\u5b78\u5f0f\u5b50\u6210\u7acb\uff0c\u6240\u4ee5\u9700\u8981\u7528 int \u4f86\u5c07\u5b57\u4e32\u8f49\u63db\u6210\u6574\u6578\u518d\u9032\u884c\u904b\u7b97\u3002

    \u90a3\u4e0b\u9762\u9019\u500b\u7a0b\u5f0f\u78bc\u7684\u8f38\u51fa\u7d50\u679c\u662f\u4ec0\u9ebc\u5462?

    x = input(\"Enter a number: \")\nprint(type(x))\ny = input(\"Enter another number: \")\nz = x + y\nprint(\"The sum is: \", z)\n

    \u6c92\u932f\uff0c\u5b57\u4e32\u7684\u76f8\u52a0\uff0c\u5c31\u662f\u76f8\u9023\u3002\u90a3\u4f60\u8981\u4e0d\u8981\u8a66\u8a66\u770b\u76f8\u6e1b?

    \u63a5\u4e0b\u4f86\u6211\u5011\u4f86\u505a\u500b\u6709\u8da3\u7684\u5be6\u9a57\uff0c\u9806\u4fbf\u8a8d\u8b58\u4e00\u4e0b f-string

    a = 3.5\nb = int(a)\nprint(f'The value of b is {b}, and its type is {type(b)}')\nc = float(b)\nprint(f'The value of c is {c}, and its type is {type(c)}')\nprint(b == c)\n

    \u90a3 f-string \u662f\u4ec0\u9ebc\u6771\u897f\u5462?\u4ed6\u662f\u4e00\u7a2e\u5b57\u4e32\u683c\u5f0f\u5316(String Formatting)\u7684\u65b9\u6cd5\uff0c\u4ed6\u6703\u5c07\u62ec\u865f\u5167\u7684\u6771\u897f\u8f49\u63db\u6210\u5b57\u4e32\uff0c\u4e26\u5c07\u5b57\u4e32\u4e2d\u7684 {} \u66ff\u63db\u6210\u62ec\u865f\u5167\u7684\u6771\u897f\u3002

    \u800c\u57f7\u884c\u5b8c\u7a0b\u5f0f\u78bc\u5f8c\uff0c\u4f60\u6703\u767c\u73fe b \u8207 c \u7684\u985e\u5225\u4e0d\u540c\uff0c\u4f46\u4ed6\u5011\u7684\u503c\u537b\u76f8\u540c\uff0c\u9019\u662f\u56e0\u70ba int() \u8207 float() \u90fd\u662f\u5c07\u62ec\u865f\u5167\u7684\u6771\u897f\u8f49\u63db\u6210\u6574\u6578\u8207\u6d6e\u9ede\u6578\uff0c\u800c int() \u6703\u5c07\u6d6e\u9ede\u6578\u7684\u5c0f\u6578\u9ede\u6368\u53bb\uff0c\u800c float() \u5247\u6703\u5c07\u6574\u6578\u8f49\u63db\u6210\u6d6e\u9ede\u6578\u3002

    \u90a3\u9ebc b == c \u662f\u4ec0\u9ebc\u610f\u601d\u5462?\u5176\u4e2d == \u662f\u6bd4\u8f03\u904b\u7b97\u5b50(Comparison Operator)\uff0c\u4ed6\u6703\u6bd4\u8f03\u7b49\u865f\u5de6\u53f3\u5169\u908a\u7684\u6771\u897f\u662f\u5426\u76f8\u7b49\uff0c\u5982\u679c\u76f8\u7b49\uff0c\u5247\u56de\u50b3 True\uff0c\u5426\u5247\u56de\u50b3 False\u3002

    "},{"location":"fundamental/python/variable_and_input/#multiple_input","title":"Multiple Input","text":"

    \u90a3\u5982\u679c\u6211\u4eca\u5929\u60f3\u8981\u4e00\u6b21\u8f38\u5165\u597d\u5e7e\u500b\u5b57\u4e32\uff0c\u6bcf\u4e00\u500b\u5b57\u4e32\u4ee5\u7a7a\u683c\u4f86\u9694\u958b\u5462? \u4f46\u5728\u9019\u4e4b\u524d\uff0c\u6211\u5011\u5148\u4f86\u770b\u4e00\u500b\u5c0f\u7a0b\u5f0f :

    a, b = \"Hello World\".split()\nprint(a)\nprint(b)\n

    \u6211\u77e5\u9053\u602a\u602a\u7684\uff0c\u70ba\u4ec0\u9ebc\u5b57\u4e32\u5f8c\u9762\u63a5\u4e86\u4e00\u500b .split() \u5462?\u5728\u9019\u88e1\u4ed6\u5f88\u50cf\u662f\u51fd\u5f0f\uff0c\u4f46\u53c8\u4e0d\u662f\u51fd\u5f0f\uff0c\u90a3\u4ed6\u53eb\u4ec0\u9ebc\u5462?\u4ed6\u88ab\u7a31\u70ba \"Hello World\" \u9019\u500b\u5b57\u4e32\u7684\u65b9\u6cd5(Method)\uff0c\u4f46\u672a\u4f86\u4f60\u53ef\u80fd\u9084\u6703\u807d\u5230\u985e\u5225\u65b9\u6cd5(Class Method)\uff0c\u4ee5\u53ca\u975c\u614b\u65b9\u6cd5(Static Method) \u7b49\u540d\u8a5e\uff0c\u6211\u6015\u4f60\u6703\u641e\u6df7\uff0c\u6240\u4ee5\u4f60\u5c31\u5148\u8a8d\u9017\u9ede\u5f8c\u9762\u7684\u662f\u300c\u65b9\u6cd5\u300d\u5c31\u597d\u4e86\u3002

    \u800c .split() \u6703\u628a\u5b57\u4e32\u4ee5\u62ec\u865f\u5167\u7684\u6771\u897f\u4f86\u5207\u5272\u5b57\u4e32\u4e26\u56de\u50b3(\u90a3\u4f60\u60f3\u60f3\u62ec\u865f\u5167\u4ec0\u9ebc\u90fd\u6c92\u653e\uff0c\u9810\u8a2d\u6703\u662f\u4ec0\u9ebc?)\uff0c\u800c\u770b\u770b\u7b49\u865f\u5de6\u908a\uff0c\u6211\u7528 a, b \u53bb\u63a5\u8457\uff0c\u9019\u7a31\u70ba\u958b\u7bb1(Unpacking)

    \u90a3\u73fe\u5728\u4f60\u61c9\u8a72\u80fd\u770b\u61c2\u4e0b\u9762\u7684\u7a0b\u5f0f\u78bc\u4e86\uff0c\u56e0\u70ba input() \u4e5f\u6703\u56de\u50b3\u4e00\u500b\u5b57\u4e32\uff0c\u56e0\u6b64\u4ed6\u4e5f\u80fd\u5920\u4f7f\u7528 .split()

    a, b = input().split()\nprint(a)\nprint(b)\n

    Note

    1. input() \u63a5\u53d7\u8f38\u5165\uff0c\u56de\u50b3\u4e00\u500b\u5b57\u4e32\u3002
    2. int(x) \u5c07 x \u8f49\u63db\u6210\u6574\u6578\u3002
    3. float(x) \u5c07 x \u8f49\u63db\u6210\u6d6e\u9ede\u6578\u3002
    4. str.split() \u4ee5\u62ec\u865f\u5167\u7684\u6771\u897f\u4f86\u5207\u5272\u5b57\u4e32\uff0c\u4e26\u56de\u50b3\u3002

    @EditTime : 2024-01-25 22:13

    Question

    1. print(int(input()) + int(input())) \u6703\u5370\u51fa\u4ec0\u9ebc?
    2. 124.spilt(\"1\") \u662f\u5408\u6cd5\u7684\u55ce?
    3. bool(0) \u8207 bool(1) \u6703\u56de\u50b3\u4ec0\u9ebc?
    4. \u770b\u4ee5\u4e0b\u7684\u7a0b\u5f0f\u78bc\uff0c\u70ba\u4ec0\u9ebc\u5b83\u5011\u7684\u529f\u80fd\u76f8\u540c\uff0ca \u8207 b \u6210\u529f\u4e92\u63db\u4e86\u5462?
    a, b = 4, 5\nprint(a, b)\na, b = b, a\nprint(a, b)\n
    a, b = 4, 5\nprint(a, b)\ntmp = a\na = b\nb = tmp\nprint(a, b)\n

    @EditTime : 2024-01-25 22:17

    "},{"location":"fundamental/python/variable_and_input/#practice","title":"Practice","text":"

    \u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u4f60\u5b78\u5230\u4e86:

    Info

    1. \u5982\u4f55\u4f7f\u7528 print() \u8207 input()\u3002
    2. \u77e5\u9053\u8b8a\u6578\u7684\u6982\u5ff5\u3002
    3. \u77e5\u9053 type(x) \u8207 int(x), float(x) \u7684\u7528\u9014\u3002
    4. \u77e5\u9053 str.split() \u7684\u7528\u9014\u3002
    5. \u77e5\u9053\u5982\u4f55\u4f7f\u7528 f-string\u3002

    \u90a3\u73fe\u5728\u4f60\u53ef\u4ee5\u8a66\u8a66\u770b\u4ee5\u4e0b\u7684\u984c\u76ee\u4e86\u3002

    ZeroJudge - a001. \u54c8\u56c9

    Reference code
    word = input()\nprint(f'hello, {word}')\n

    @EditTime : 2024-01-27 17:02

    "}]} \ No newline at end of file +{"config":{"lang":["en"],"separator":"[\\s\\u200b\\u3000\\-\u3001\u3002\uff0c\uff0e\uff1f\uff01\uff1b]+","pipeline":["stemmer"]},"docs":[{"location":"","title":"Hello LMcps Book!","text":""},{"location":"#welcome_to_lmcps","title":"Welcome to LMcps!","text":"

    \u9ece\u660e\u8cc7\u8a0a\u793e(LMcps)\u5275\u7acb\u65bc2018\u5e74\uff0c\u6307\u5c0e\u8005\u70ba\u674e\u60e0\u6587\u8001\u5e2b\u3002

    \u672c\u66f8\u7684\u6b63\u78ba\u6253\u958b\u65b9\u5f0f\u662f\u6697\u8272\u6a21\u5f0f\u3002

    print(\"Hello LMcps Book!\")\nprint(\"Welcome to LMcps!\")\n
    "},{"location":"#why_does_it_start","title":"Why does it start?","text":"

    \u57282024/1/25\uff0c\u662f\u75ab\u60c5\u5f8c\uff0c\u7b2c\u4e00\u6b21\u6b77\u5c46\u793e\u54e1\u8fd4\u56de\u6bcd\u6821\u8207\u5b78\u5f1f\u59b9\u5011\u5206\u4eab\u7d93\u9a57\u7684\u65e5\u5b50\uff0c\u5728\u8207\u8001\u5e2b\u53ca\u5b78\u5f1f\u59b9\u5011\u4ea4\u6d41\u5f8c\uff0c\u767c\u73fe\u4e86\u76ee\u524d\u8cc7\u8a0a\u6559\u80b2\u7684\u7a98\u56f0\uff0c\u8af8\u5982\u7db2\u8def\u4e0a\u7684\u8cc7\u6e90\u96d6\u591a\uff0c\u4f46\u4e0d\u6613\u5165\u9580\uff0c\u65bc\u662f\u6c7a\u5b9a\u5beb\u4e00\u672c\u66f8\uff0c\u4ee5\u5927\u91cf\u7684\u5716\u7247\u53ca\u7c21\u55ae\u7684\u6587\u5b57\uff0c\u8b93\u5b78\u5f1f\u59b9\u5011\u80fd\u5920\u5feb\u901f\u5165\u9580\uff0c\u4e26\u4e14\u80fd\u5920\u5728\u77ed\u6642\u9593\u5167\uff0c\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\u8207\u81ea\u4fe1\u3002

    "},{"location":"#content","title":"Content","text":"

    \u9019\u672c\u66f8\u8457\u91cd\u65bc\u61c9\u7528\u9762\uff0c\u4e26\u4e14\u5be6\u4f5c\u70ba\u4e3b\uff0c\u4e5f\u4e26\u975e\u5e36\u4f60\u6253\u7af6\u7a0b\uff0c\u800c\u662f\u5e36\u4f60\u4e86\u89e3\u91cd\u8981\u7684\u8cc7\u6599\u7d50\u69cb\u8207\u6f14\u7b97\u6cd5\u3002\u5be6\u4f5c\u8a9e\u8a00\u4ee5Python\u70ba\u4e3b\uff0c\u6703\u6709\u5c11\u6578C++\u7684\u5be6\u4f5c\u3002

    "},{"location":"#wait_to_be_done","title":"Wait to be done","text":"
    1. \u5fc3\u5f97\u5206\u4eab\u5c08\u5340
    2. \u5c08\u696d\u7528\u8a9e
    "},{"location":"#contributors","title":"Contributors","text":""},{"location":"license/","title":"License","text":"

    MIT License

    Copyright (c) 2023 Cheung4843

    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

    "},{"location":"blog/","title":"Blog","text":""},{"location":"blog/2024/02/06/hello-blog-/","title":"Hello Blog !","text":"

    Hi, this is a test post.

    For the better experience of the development, I think recording the process of the development is a good idea.

    If you are interested in the project, you can follow the blog to get the latest information about the project.

    Also, plaease contact me if you wanna join the project. I am looking forward to working with you.

    "},{"location":"fundamental/","title":"Fundamental","text":"

    \u9019\u88e1\u5c07\u6703\u6559\u4f60\u57fa\u790e\u7684Python\u8207C++\u7684\u57fa\u790e\u8a9e\u6cd5\u3002

    "},{"location":"fundamental/cpp/","title":"C++","text":"

    \u6211\u662fc++\u7cfb\u5217\u7684\u7b46\u8005bloodnighttw\uff0c\u6211\u9810\u8a08\u5728\u6b64\u6587\u7ae0\u5206\u4e0b\u5217\u5e7e\u500b\u7ae0\u7bc0\uff0c\u4e26\u76e1\u91cf\u4ee5\u521d\u5b78\u8005\u7684\u89d2\u5ea6\u5beb\u51fa\u5167\u5bb9\u3002

    1. \u74b0\u5883\u67b6\u8a2d
    2. Hello world (\u57fa\u672c\u8f38\u51fa\u5165)
    3. \u578b\u614b\u3001\u8b8a\u6578\u8207\u76f8\u95dc\u904b\u7b97
    4. \u6d41\u7a0b\u63a7\u5236
    5. \u8ff4\u5708
    6. \u51fd\u5f0f
    7. struct & class
    8. \u6307\u6a19\u8207\u53c3\u7167
    9. standard template libary

    \u5982\u679c\u5728\u64b0\u5beb\u4e0a\u6709\u4efb\u4f55\u554f\u984c\uff0c\u4f60\u53ef\u4ee5\u5bc4\u96fb\u5b50\u90f5\u4ef6\u5230 bbeenn1227@gmail.com \u6216\u8005 emails@bntw.dev \u4f86\u505a\u8a62\u554f(\u4e0d\u904e\u8acb\u8868\u660e\u4f60\u7684\u8eab\u4efd\uff0c\u4e0d\u7136\u6211\u53ef\u80fd\u6703\u5ffd\u7565)\uff0c\u6216\u8005\u53ef\u4ee5\u5728\u6211\u66f4\u5e38\u51fa\u73fe\u7684discord\u8a62\u554f\u6211\u3002

    \u6b64\u9023\u7d50\u70ba\u9ece\u660e\u8cc7\u8a0a\u793e\u7684discord\u7fa4\u7d44\u9023\u7d50\uff0c\u52a0\u5165\u4e4b\u5f8c\u53ef\u4ee5tag @bloodnighttw\uff0c\u53ea\u8981\u6211\u5728\u7dda\u4e0a\u4e14\u6709\u6642\u9593\u6211\u90fd\u6703\u76e1\u91cf\u5e6b\u4f60\u56de\u7b54\u3002

    \u53e6\u5916\u6709\u4efb\u4f55\u932f\u5b57\u6216\u53ef\u4ee5\u6539\u5584\u7684\u5730\u65b9\u8acb\u767cissues\uff0c\u6211\u5011\u6703\u518d\u8a0e\u8ad6\u904e\u5f8c\u9069\u6642\u5730\u505a\u51fa\u4fee\u6b63\u3002

    "},{"location":"fundamental/cpp/create_env/","title":"0. \u74b0\u5883\u67b6\u8a2d","text":"

    \u6b63\u6240\u8b02\u5de5\u6b32\u5584\u5176\u4e8b\uff0c\u5fc5\u5148\u5229\u5176\u5668\uff0c\u6b64\u7ae0\u6211\u5011\u5206\u5225\u6703\u5728\u5206\u5225\u8b1b\u8ff0\u5982\u4f55\u5728windows\u3001macos\u4e0a\u5b89\u88dd\u76f8\u95dc\u5957\u4ef6\u3002

    \u6211\u5011\u9810\u8a08\u8981\u4f7f\u7528GNU C++ Compiler\u9032\u884c\u7de8\u8b6f\uff0c\u4ee5\u53ca\u4f7f\u7528Visual studio code + clangd\u8207c++11\u7684\u6a19\u6e96\u64b0\u5beb\u7a0b\u5f0f\uff0c\u4e0b\u9762\u6703\u8a73\u8ff0\u5b89\u88dd\u6d41\u7a0b\u3002

    \u7576\u7136\uff0c\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528\u50cf\u662fdev c++\u3001codeblock\u9019\u985e\u7684\u8edf\u9ad4\u9032\u884c\u64b0\u5beb\uff0c\u53ea\u4e0d\u904e\u6709\u4e00\u9ede\u9700\u8981\u6ce8\u610f\uff0c\u820a\u7248\u7684dev c++\u9810\u8a2d\u6c92\u6709\u555f\u7528c++11\u6a19\u6e96\u7684\u652f\u63f4\uff0c\u4f60\u5fc5\u9808\u8981\u5728\u8a2d\u5b9a\u88e1\u9762\u5c0b\u627e\u958b\u555f\u7684\u65b9\u5f0f\u3002

    "},{"location":"fundamental/cpp/create_env/#windows","title":"Windows","text":"

    GNU C++ Compiler (G++)\u672c\u8eab\u662f\u6c92\u6709\u652f\u63f4Windows\u7684\uff0c\u4f46\u6211\u5011\u53ef\u4ee5\u900f\u904e\u4f7f\u7528wsl2\u6216\u8005\u5225\u4eba\u7528\u597d\u7684\u79fb\u690d\u7248\u672c\u9032\u884c\u4f7f\u7528\uff0c\u9019\u908a\u6211\u5011\u6703\u5b89\u88dd\u5225\u4eba\u5beb\u597d\u7684\u79fb\u690d\u7248\u3002

    "},{"location":"fundamental/cpp/create_env/#1mingw","title":"1.\u4e0b\u8f09\u4e26\u5b89\u88ddmingw","text":"
    1. \u524d\u5f80\u9019\u500b\u9023\u7d50\u5b89\u88ddmingw
    2. \u52fe\u9078 mingw32-gcc-g++
    3. installation > apply change
    4. \u6309\u4e0bapply\u5b89\u88dd

    "},{"location":"fundamental/cpp/create_env/#2","title":"2. \u52a0\u5165\u74b0\u5883\u8b8a\u6578","text":"
    1. \u5c0b\u627e\u5b89\u88dd\u4f4d\u7f6e\uff0c\u4ee5\u6211\u70ba\u4f8b\uff0c\u662f\u5b89\u88dd\u5728C:\\MinGW\u88e1\u9762\uff0c\u627e\u5230\u88e1\u9762\u7684bin\u8cc7\u6599\u593e\uff0c\u9ede\u9032\u53bb\u4e26\u8907\u88fd\u8def\u5f91\u3002
    2. \u641c\u5c0b\u74b0\u5883\u8b8a\u6578\uff0c\u4e26\u9032\u53bb\u7de8\u8f2f\u74b0\u5883\u8b8a\u6578\u3002
    3. \u9ede\u5165 \u9032\u968e >\u74b0\u5883\u8b8a\u6578\uff0c\u4e26\u5728Path\u4e2d\u8cbc\u4e0a\u525b\u624d\u8907\u88fd\u7684\u8b8a\u6578\uff0c\u7136\u5f8c\u4fdd\u5b58\u9000\u51fa\u3002

    "},{"location":"fundamental/cpp/create_env/#3","title":"3. \u6e2c\u8a66\u6307\u4ee4","text":"

    \u958b\u555f\u63d0\u793a\u547d\u4ee4\u5b57\u5143\u5f8c\uff0c\u6253\u5165g++ -v\uff0c\u5982\u679c\u6709\u7248\u672c\u8a0a\u606f\u4ee3\u8868\u5b89\u88dd\u6210\u529f\u3002

    "},{"location":"fundamental/cpp/create_env/#macos","title":"macOS","text":"

    macos\u672c\u8eab\u5c31\u6709\u63d0\u4f9bclangd\u4f5c\u70ba\u7de8\u8b6f\u5668\u4f7f\u7528\uff0c\u5728\u5b89\u88ddxcode\u5f8c\u61c9\u8a72\u5c31\u53ef\u4ee5\u4f7f\u7528\uff0c\u5982\u679c\u9084\u662f\u9700\u8981GNU C++ Compiler\uff0c\u8acb\u53c3\u8003\u4e0b\u9762\u6b65\u9a5f\u3002

    "},{"location":"fundamental/cpp/create_env/#1homwbrew","title":"1.\u5b89\u88ddhomwbrew\u5957\u4ef6\u7ba1\u7406\u5668","text":"

    \u6839\u64da\u5b98\u7db2\u7684\u6307\u793a\u5b89\u88ddhomebrew\u3002

    "},{"location":"fundamental/cpp/create_env/#2g","title":"2.\u4f7f\u7528\u7ba1\u7406\u5668\u5b89\u88ddg++\u5957\u4ef6","text":"
    1. \u5148\u4f7f\u7528brew search gcc\u641c\u5c0b\u76f8\u95dc\u5957\u4ef6
    2. \u4f7f\u7528 brew install gcc\u5b89\u88ddCompiler
    3. \u4f7f\u7528gcc-13 -v\u6216g++-13\u78ba\u8a8d\u662f\u5426\u6210\u529f\u5b89\u88dd

    Warning

    \u8acb\u6ce8\u610f\uff0c\u5728macos\u4e0a\u9810\u8a2d\u4f7f\u7528\u7684g++\u6307\u4ee4\u70baclang\u800c\u4e0d\u662fGNU C++ Compiler\uff0c\u8acb\u6539\u4f7f\u7528g++-XX \u4f86\u64cd\u4f5cg++\u7de8\u8b6f\u5668\u3002

    "},{"location":"fundamental/cpp/create_env/#visual_studio_code","title":"Visual Studio Code","text":""},{"location":"fundamental/cpp/create_env/#1_visual_studio_code","title":"1. \u5b89\u88ddVisual Studio Code","text":"

    \u524d\u5f80\u9019\u500b\u7db2\u7ad9\u4e0b\u8f09\u5c6c\u65bc\u4f60\u7cfb\u7d71\u7684visual studio code\u5b89\u88dd\u6a94\u3002

    "},{"location":"fundamental/cpp/create_env/#2_extension","title":"2. \u5b89\u88dd extension","text":"
    1. \u9ede\u5165extension\u9801\u9762\u5206\u5225\u5b89\u88ddC/C++ clangd \u9019\u5169\u500bextension\uff0c\u4e26\u91cd\u555fvscode
    2. \u4f60\u53ef\u80fd\u9047\u5230\u9019\u6a23\u7684\u8b66\u544a\u8a0a\u606f\uff0c\u8acb\u6309\u4e0b Disable Intellisence
    "},{"location":"fundamental/cpp/create_env/#_1","title":"\u5176\u4ed6","text":"

    \u5982\u679c\u9047\u5230\u5b57\u9ad4\u975e\u7b49\u5bec\uff0c\u8acb\u5c0b\u627e\u4e00\u500b\u7b49\u5bec\u5b57\u9ad4\u4e26\u4f7f\u7528\uff0c\u7b49\u5bec\u5b57\u9ad4\u53ef\u4ee5\u8b93\u4f60\u7684\u7a0b\u5f0f\u78bc\u53ef\u8b80\u6027\u66f4\u4f73\u3002

    "},{"location":"fundamental/cpp/hello_world/","title":"1. Hello World","text":""},{"location":"fundamental/cpp/hello_world/#hello_world","title":"Hello World (\u8f38\u51fa)","text":""},{"location":"fundamental/cpp/hello_world/#_1","title":"\u521d\u5b78\u8005\u7684\u7b2c\u4e00\u6b65","text":"

    \u9996\u5148\uff0c\u8acb\u5728vscode (Visual studio code)\u4e2d\u65b0\u589e\u4e00\u500b\u540d\u70bahello_world.cpp\uff0c\u4e26\u6253\u5165\u4e0b\u5217\u7a0b\u5f0f\u78bc\u3002

    #include <iostream>\n\nusing namespace std;\n\nint main(){\n    cout << \"hello world!\" << endl;\n    return 0;\n}\n
    \u78ba\u8a8d\u597d\u5b58\u6a94\u904e\u5f8c\uff0c\u6309\u4e0b\u53f3\u4e0a\u89d2\u7684\u57f7\u884c\u6309\u9375\uff0c\u4f60\u5c31\u6703\u6210\u529f\u770b\u5230\u4f60\u5beb\u7684\u7b2c\u4e00\u652f\u7a0b\u5f0f\u3002

    \u63a5\u8457\uff0c\u6211\u5011\u5c07\u66f4\u6df1\u5165\u8a0e\u8ad6\u9019\u6bb5\u7a0b\u5f0f\uff0c\u5230\u5e95\u767c\u751f\u4e86\u4ec0\u9ebc\u4e8b\u60c5\u3002

    "},{"location":"fundamental/cpp/hello_world/#hello_world_1","title":"Hello World\u7a0b\u5f0f\u89e3\u91cb","text":"

    \u5728\u9019\u6bb5\u7a0b\u5f0f\u4e2d\uff0c\u5df2\u7d93\u6709\u8a31\u591a\u7a0d\u5fae\u8907\u96dc\u7684\u6982\u5ff5\uff0c\u5148\u5225\u6015\uff0c\u6211\u5011\u5c31\u53ea\u8981\u4e86\u89e3\u5230:

    1. \u7a0b\u5f0f\u4e00\u5b9a\u662f\u5f9eint main(){......}\u88e1\u9762\u958b\u59cb\u57f7\u884c\u7684
    2. \u6700\u5f8c\u4e00\u5b9a\u6703\u6709\u500breturn 0; \u4ee3\u8868\u7a0b\u5f0f\u6210\u529f\u7d50\u675f\u3002

    \u8b93\u6211\u5011\u7126\u9ede\u653e\u5728\u7b2c\u516d\u884c:

    #include <iostream>\n\nusing namespace std;\n\nint main(){\n    cout << \"hello world!\" << endl;\n    return 0;\n}\n

    \u9019\u908a\u6709\u4e86\u6211\u5011\u7684\u7b2c\u4e00\u652f\u7a0b\u5f0f\uff0c\u4f60\u53ef\u4ee5\u628acout\u7576\u6210\u96fb\u8166\u87a2\u5e55\u7684\u6587\u5b57\u5370\u8868\u6a5f\uff0c\u628a<<\u7576\u6210\u50b3\u905e\u7684\u7bad\u982d\uff0c\u800c\u9019\u6bb5\u7a0b\u5f0f\u5c31\u662f\u8981\u628a\u9019\u6bb5\u5b57\u50b3\u7d66\u96fb\u8166\u5370\u51fa\u3002

    \u9019\u908a\u7684endl\u4ee3\u8868\u8457\u63db\u884c\u7684\u610f\u601d\uff0c\u900f\u904e<<\u50b3\u7d66\u96fb\u8166\u87a2\u5e55\u7684\u6587\u5b57\u5370\u8868\u6a5f\u3002

    \u53e6\u5916\u4e00\u500b\u5beb\u6cd5

    \u9019\u908a\u63d0\u4f9b\u53e6\u5916\u4e00\u500b\u63db\u884c\u7684\u5beb\u6cd5\uff0c\u5177\u9ad4\u5dee\u7570\u5728\u719f\u6089\u8a9e\u6cd5\u5f8c\uff0c\u6703\u5728\u53e6\u5916\u4e00\u7bc7\u6587\u7ae0\u505a\u8aaa\u660e\u3002

    #include <iostream>\n\nusing namespace std;\n\nint main(){\n    cout << \"hello world!\\n\";\n    return 0;\n}\n
    \\n\u70ba\u63db\u884c\u5b57\u5143\uff0c\u5728\u5b57\u5143\u4e2d\u6709\u8a31\u591a\u5b57\u5143\u6703\u6709\u7279\u5b9a\u529f\u7528\uff0c\u6703\u4ee5\\\u958b\u982d\uff0c\u9023\u7d50\u4e00\u500b\u5b57\u6bcd\u6216\u6578\u5b57\uff0c\u4ee3\u8868\u8457\u8df3\u812b\u5b57\u5143\uff0c\u4f5c\u70ba\u7279\u6b8a\u7528\u9014\u4f7f\u7528\u3002

    \u7d30\u5fc3\u5982\u4f60\uff0c\u9019\u662f\u53c8\u8981\u63d0\u554f\u4e86\uff0c\u5206\u865f;\u53c8\u4ee3\u8868\u4ec0\u9ebc\u610f\u601d\uff1f

    \u5206\u865f;\u662f\u544a\u8a34\u96fb\u8166\u8aaa\uff0c\u9019\u4e9b\u6307\u4ee4\u8ddf\u4e0b\u4e00\u500b\u5b57\u5143\u6216\u4e0b\u4e00\u884c\u662f\u5206\u958b\u7684\uff0c\u4e0d\u8981\u628a\u4ed6\u9023\u5728\u4e00\u8d77\uff0c\u4e5f\u56e0\u70ba\u6709\u9019\u6771\u897f\uff0c\u6211\u5011\u7a0b\u5f0f\u53ef\u4ee5\u9019\u6a23\u5beb\u3002

    #include <iostream>\n\nusing namespace std;\n\nint main(){\n    cout << \"hello world!\\n\"; cout << endl;\n    return 0;\n}\n

    Danger

    \u5341\u5206\u4e0d\u5efa\u8b70\u4f60\u9019\u6a23\u5beb\uff0c\u5c0d\u65bc\u7a0b\u5f0f\u719f\u7df4\u7684\u4eba\u4f86\u8aaa\uff0c\u9019\u6a23\u7684\u6392\u7248\uff0c\u7a0b\u5f0f\u78bc\u8b80\u8d77\u4f86\u6703\u975e\u5e38\u75db\u82e6\uff0c\u5c0d\u65bc\u521d\u5b78\u8005\uff0c\u5247\u5bb9\u6613\u8aa4\u89e3\u7a0b\u5f0f\u78bc\u3002

    "},{"location":"fundamental/cpp/hello_world/#_2","title":"\u52a0\u5165\u8b8a\u6578 (\u8f38\u5165)","text":""},{"location":"fundamental/cpp/hello_world/#_3","title":"\u8b80\u53d6\u5b57\u4e32","text":"
    #include <iostream>\n\nusing namespace std;\n\nint main(){\n    string str;\n    cin >> str;\n    cout << str << endl;\n    return 0;\n}\n

    \u6309\u4e0b\u57f7\u884c\uff0c\u6253\u5165\u96a8\u4fbf\u4e00\u4e32\u6587\u5b57\uff0c\u6309\u4e0benter\uff0c\u4f60\u6703\u767c\u73fe\u4f60\u6253\u7684\u6587\u5b57\u88ab\u5370\u5728\u87a2\u5e55\u4e0a\u3002

    "},{"location":"fundamental/cpp/hello_world/#_4","title":"\u8b80\u53d6\u6578\u5b57","text":"

    \u5047\u5982\u4eca\u5929\u6211\u5011\u8f38\u5165\u7684\u6578\u5b57\uff0c\u5247\u7a0b\u5f0f\u78bc\u6539\u6210\u9019\u6a23:

    #include <iostream>\n\nusing namespace std;\n\nint main(){\n    int temp;\n    cin >> temp;\n    cout << temp << endl;\n    return 0;\n}\n

    \u6309\u4e0b\u57f7\u884c\uff0c\u6253\u5165\u96a8\u4fbf\u4e00\u500b\u6578\u5b57\uff0c\u6309\u4e0benter\uff0c\u4f60\u6703\u767c\u73fe\u4f60\u6253\u7684\u4e00\u4e32\u6578\u5b57\u88ab\u5370\u5728\u87a2\u5e55\u4e0a\u3002

    Info

    \u5982\u679c\u4eca\u5929\u6253\u5165\u7684\u6578\u5b57\u975e\u5e38\u975e\u5e38\u7684\u5927\uff0c\u4f60\u53ef\u80fd\u6703\u767c\u73fe\u5370\u51fa\u4f86\u7684\u6578\u5b57\u8ddf\u6253\u5165\u7684\u6578\u5b57\u4e0d\u4e00\u6a23\uff0c\u5176\u539f\u56e0\u662f\u6ea2\u4f4d\uff0c\u9019\u9ede\u6211\u5011\u6703\u5728\u4e0b\u4e00\u7ae0\u8ac7\u5230\u5176\u539f\u56e0\u8207\u89e3\u6cd5\u3002

    "},{"location":"fundamental/cpp/hello_world/#_5","title":"\u8f38\u5165\u7a0b\u5f0f\u89e3\u91cb","text":"

    \u6b63\u5982cout\u4e00\u6a23\uff0c\u4f60\u53ef\u4ee5\u628acin\u7576\u6210\u4f60\u7684\u9375\u76e4\uff0c\u900f\u904e>>\u544a\u8a34\u96fb\u8166\u5f9e\u9375\u76e4\u8f38\u5165\u81f3\u53f3\u908a\u7684\u8b8a\u6578\u3002

    \u5e38\u898b\u7684\u8aa4\u5340

    \u5c0d\u65bc\u521d\u5b78\u8005\u4f86\u8aaa\uff0c\u53ef\u80fd\u6703\u4e0d\u5c0f\u5fc3\u5beb\u51fa\u9019\u6a23\u7684\u7a0b\u5f0f\uff1a

    #include <iostream>\n\nusing namespace std;\n\nint main(){\n    int temp1,temp2;\n    cin << temp1 << temp2;\n    cout << temp1 << \"!=\" << temp2 << endl;\n    return 0;\n}\n

    \u6b64\u6642\u4f60\u6703\u767c\u73fe\u7121\u6cd5\u7de8\u8b6f\uff0c\u5176\u539f\u56e0\u662f\u4f60\u7684cin\u7684<<\u61c9\u8a72\u8981\u662f>>\u624d\u5c0d \u3002

    \u5e38\u898b\u7684\u932f\u8aa4\u4e5f\u5305\u62ec\u4e0b\u9762\u7684\u4f8b\u5b50\uff1a

    1. cout\u7684<< \u65b9\u5411\u932f\u8aa4
      #include <iostream>\n\nusing namespace std;\n\nint main(){\n    int temp1,temp2;\n    cin >> temp1 >> temp2;\n    cout >> temp1 >> temp2;\n    return 0;\n}\n
    2. cout\u7684\u4f4d\u7f6e\u932f\u8aa4

      #include <iostream>\n\nusing namespace std;\n\nint main(){\n    \"error\" >> cout;\n    return 0;\n}\n
      cout \u53ea\u80fd\u653e\u5728\u5de6\u908a\u554a\u3002

    3. cin\u7684\u4f4d\u7f6e\u932f\u8aa4

      #include <iostream>\n\nusing namespace std;\n\nint main(){\n    int a;\n    a << cin;\n    return 0;\n}\n
      \u539f\u56e0\u540c\u4e0a\uff0ccin\u53ea\u80fd\u653e\u5728\u5de6\u908a\u554a\u3002

    "},{"location":"fundamental/cpp/hello_world/#_6","title":"\u9023\u7e8c\u8b80\u53d6\u6578\u5b57/\u5b57\u4e32","text":"

    \u5047\u5982\u4eca\u5929\u6211\u5011\u8f38\u5165\u7684\u4e00\u9023\u6578\u5b57\uff0c\u5247\u7a0b\u5f0f\u78bc\u6539\u6210\u9019\u6a23\u3002

    #include <iostream>\n\nusing namespace std;\n\nint main(){\n    int temp1;\n    string temp2;\n    cin >> temp1 >> temp2;\n    cout << temp1 << \"!=\" << temp2 << endl;\n    return 0;\n}\n
    input
    1234 4321\n
    output
    1234!=4321\n

    \u4f60\u6703\u767c\u73fe\u4e00\u4ef6\u4e8b\u60c5\uff0ccin\u662f\u900f\u904e\u7a7a\u683c\u6216\u8005\u63db\u884c\u4f86\u5206\u958b\u7684\uff0c\u4eca\u5929\u5982\u679c\u60f3\u8981\u8b80\u53d6\u4e00\u884c\uff0c\u8acb\u53c3\u8003\u4e0b\u65b9\u7a0b\u5f0f\u3002

    "},{"location":"fundamental/cpp/hello_world/#_7","title":"\u8b80\u53d6\u4e00\u884c","text":"

    \u7a0b\u5f0f\u78bc\u5982\u4e0b\uff0c\u5176\u4e2dtemp2\u8acb\u6539\u6210\u8b8a\u6578\u7684\u540d\u7a31\u3002

    #include <iostream>\n\nusing namespace std;\n\nint main(){\n    string temp2;\n    getline(cin,temp2);\n    cout << temp2 << endl;\n    return 0;\n}\n
    "},{"location":"fundamental/cpp/hello_world/#practice","title":"Practice","text":"

    \u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u4f60\u5b78\u5230\u4e86:

    Info

    1. \u5982\u4f55\u4f7f\u7528 cout\u8207cin
    2. \u63a5\u89f8\u8b8a\u6578\u7684\u6982\u5ff5\u3002

    \u90a3\u73fe\u5728\u4f60\u53ef\u4ee5\u8a66\u8a66\u770b\u4ee5\u4e0b\u7684\u984c\u76ee\u4e86\u3002

    ZeroJudge - a001. \u54c8\u56c9

    Reference code
    #include <iostream>\n\nint main(){\n    string word;\n    cin >> word;\n    cout << \"hello, \" << word << endl;\n\n    return 0;\n}\n
    "},{"location":"fundamental/python/","title":"Python","text":"

    \u55e8\uff0c\u6211\u662f @cheung4843\uff0c\u662fPython\u7cfb\u5217\u7684\u4f5c\u8005\u3002\u5728\u4e00\u958b\u59cb\u57fa\u790e\u8a9e\u6cd5\u7684\u90e8\u5206\u6703\u6559\u5f97\u7279\u5225\u8a73\u7d30\uff0c\u6587\u7ae0\u4e2d\u7684\u5c08\u6709\u540d\u8a5e\u5c07\u6703\u4ee5\u9ec3\u8272\u8207\u7da0\u8272\u6a19\u793a\uff0c\u8acb\u4f60\u7a0d\u5fae\u6ce8\u610f\u4e00\u4e0b\uff0c\u82e5\u4e0d\u61c2\u4e5f\u6c92\u95dc\u4fc2\uff0c\u6211\u6703\u5728\u5f8c\u9762\u7ae0\u7bc0\u518d\u6b21\u63d0\u5230\u3002

    \u5728\u6bcf\u4e00\u500b\u5c0f\u7bc0\u7684\u5f8c\u9762\u90fd\u6703\u6709\u7b46\u8a18\u5340\u4ee5\u53ca\u554f\u984c\u5340\uff0c\u5c24\u5176\u662f\u554f\u984c\u5340\uff0c\u8acb\u4f60\u597d\u597d\u601d\u8003\u3002\u800c\u5728\u6bcf\u4e00\u7bc7\u6587\u7ae0\u6700\u5f8c\u90fd\u6703\u653e\u4e0a\u4e00\u4e9b\u7df4\u7fd2\u984c\uff0c\u8acb\u5617\u8a66\u5b8c\u6210\u4ed6\u5011!

    "},{"location":"fundamental/python/lists/","title":"Lists","text":""},{"location":"fundamental/python/lists/#introduction","title":"Introduction","text":"

    \u4e0d\u66c9\u5f97\u4f60\u770b\u5230\u9019\u88e1\u6709\u6c92\u6709\u767c\u73fe\uff0c\u6211\u5011\u5728\u524d\u9762\u7684\u7ae0\u7bc0\u4e2d\uff0c\u90fd\u662f\u7528\u4e00\u500b\u4e00\u500b\u7684\u8b8a\u6578\u4f86\u5132\u5b58\u8cc7\u6599\uff0c\u4f46\u662f\u5982\u679c\u6211\u5011\u8981\u5132\u5b58\u5f88\u591a\u7b46\u8cc7\u6599\uff0c\u9019\u6a23\u7684\u65b9\u5f0f\u5c31\u6703\u8b8a\u5f97\u5f88\u9ebb\u7169\u3002

    \u6240\u4ee5\u9019\u88e1\u8ddf\u4f60\u4ecb\u7d39 List(\u4e32\u5217)\uff0c\u5b83\u53ef\u4ee5\u8b93\u6211\u5011\u5132\u5b58\u5f88\u591a\u7b46\u8cc7\u6599\uff0c\u800c\u4e14\u53ef\u4ee5\u5132\u5b58\u4e0d\u540c\u7684\u8cc7\u6599\u578b\u614b\uff0c\u4f8b\u5982: \u6578\u5b57\u3001\u5b57\u4e32\u3001\u5e03\u6797\u503c\u7b49\u7b49\u3002

    "},{"location":"fundamental/python/lists/#create_a_list","title":"Create a list","text":"

    \u8981\u5efa\u7acb\u4e00\u500b List\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u4e2d\u62ec\u865f []\uff0c\u4e26\u5728\u4e2d\u62ec\u865f\u4e2d\u653e\u5165\u6211\u5011\u8981\u5132\u5b58\u7684\u8cc7\u6599\uff0c\u8cc7\u6599\u4e4b\u9593\u7528\u9017\u865f , \u9694\u958b\u3002

    \u4f86\u8209\u500b\u4f8b\u5b50\uff0c\u5efa\u7acb\u4e09\u500b List\uff0c\u4e00\u500b\u90fd\u5132\u5b58\u6574\u6578\uff0c\u4e00\u500b\u662f\u90fd\u5132\u5b58\u5b57\u4e32\uff1b\u6700\u5f8c\u4e00\u500b\u5247\u653e\u4e86\u4e0d\u540c\u7684\u8cc7\u6599\u578b\u614b\u3002

    numbers = [1, 2, 3, 4, 5]\nprint(numbers)\n\nwhat_i_learned = [\"C\", \"C++\", \"Python\", \"Java\", \"C#\", \"JavaScript\", \"TypeScript\"]\nprint(what_i_learned)\n\nstudent_info = [\"Sean\", 20, \"Computer Science\", 4.0, True, \"aLIEz\"]\nprint(student_info)\n\nprint(type(numbers), type(what_i_learned), type(student_info))\n
    ouput
    [1, 2, 3, 4, 5]\n['C', 'C++', 'Python', 'Java', 'C#', 'JavaScript', 'TypeScript']\n['Sean', 20, 'Computer Science', 4.0, True, 'aLIEz']\n<class 'list'> <class 'list'> <class 'list'>\n

    Sawano Hiroyuki - aLIEz Aldnoah.Zero Full Lyrics

    \u5982\u679c\u4f60\u6709\u5b78\u904e\u5176\u4ed6\u7684\u7a0b\u5f0f\u8a9e\u8a00\uff0c\u4f60\u53ef\u80fd\u6703\u807d\u904e Array(\u9663\u5217)\uff0cList \u5c31\u662f Python \u4e2d\u7684 Array\uff0c\u4f46\u53c8\u66f4\u5f37\u5927\uff0c\u56e0\u70ba List \u53ef\u4ee5\u5132\u5b58\u4e0d\u540c\u7684\u8cc7\u6599\u578b\u614b\uff0c\u800c\u901a\u5e38 Array \u53ea\u80fd\u5132\u5b58\u4e00\u7a2e\u8cc7\u6599\u578b\u614b\u3002

    \u4f46 Python \u4e5f\u6709\u63d0\u4f9b\u771f\u6b63\u7684\u300c\u9663\u5217\u300d\uff0c\u4f46\u6211\u5148\u4e0d\u63d0\uff0c\u8acb\u4f60\u7a0d\u5fae\u6709\u500b\u5370\u8c61\u5c31\u597d\u3002

    \u984c\u5916\u8a71\uff0c\u7576\u521d\u5f9e C, C++, Java \u8f49\u5230 Python \u7684\u6642\u5019\uff0c\u771f\u5fc3\u89ba\u5f97\u600e\u9ebc\u53ef\u4ee5\u9019\u9ebc\u96a8\u4fbf\uff0c\u9023\u578b\u614b\u90fd\u4e0d\u7528\u5ba3\u544a\uff0c\u73fe\u5728\u89ba\u5f97\u771f\u9999\u3002

    \u4e0d\u66c9\u5f97\u4f60\u9084\u8a18\u4e0d\u8a18\u5f97\uff0c\u6211\u5011\u5728\u524d\u9762\u7684\u7ae0\u7bc0\u4e2d\uff0c\u6709\u63d0\u5230 range \u9019\u500b\u51fd\u5f0f\uff0c\u5b83\u53ef\u4ee5\u7522\u751f\u4e00\u500b\u6574\u6578\u7684\u5e8f\u5217\uff0c\u4f8b\u5982: range(5) \u6703\u7522\u751f\u4e00\u500b\u5f9e \\(0\\) \u5230 \\(4\\) \u7684\u6574\u6578\u5e8f\u5217\u3002

    list(range(5)) \u9019\u6a23\u5c31\u53ef\u4ee5\u5c07 range \u7269\u4ef6\u8f49\u63db\u6210 List\u3002

    x = range(5)\nprint(type(x))\nnumbers = list(x)\nprint(numbers)\n
    ouput
    <class 'range'>\n[0, 1, 2, 3, 4]\n

    \u90a3\u80fd\u5426\u628a\u5b57\u4e32\u8f49\u63db\u6210 List \u5462? \u7576\u7136\u53ef\u4ee5!

    x = \"Signals\"\nprint(type(x))\nwords = list(x)\nprint(words)\n
    ouput
    <class 'str'>\n['S', 'i', 'g', 'n', 'a', 'l', 's']\n

    Lazer Boomerang - Signals (Official Audio)

    \u518d\u4f86\u770b\u4e00\u500b\u4f8b\u5b50\uff0c\u5982\u4f55\u521d\u59cb\u5316\u4e00\u500b\u5143\u7d20\u90fd\u662f \\(0\\) \u7684\u4e32\u5217\u3002

    n = 5\nzeros = [0] * n\nprint(zeros)\n
    ouput
    [0, 0, 0, 0, 0]\n

    \u5982\u4f55\u5c07\u5169\u500b\u4e32\u5217\u5408\u4f75\u6210\u4e00\u500b\u4e32\u5217\u5462?

    a = [1, 2, 3]\nb = [4, 5, 6]\nc = a + b\nprint(c)\n
    ouput
    [1, 2, 3, 4, 5, 6]\n

    \u9084\u6709\u4e00\u500b\u65b9\u6cd5\uff0c\u5c31\u662f\u4f7f\u7528 extend \u9019\u500b\u65b9\u6cd5\uff0c\u9019\u5728\u5f8c\u9762\u6703\u4ecb\u7d39\u5230\u3002

    \u6211\u76f8\u4fe1\u4ee5\u4e0a\u9019\u4e9b\u4f8b\u5b50\u80fd\u8b93\u4f60\u6293\u5230\u4e00\u4e9b\u6982\u5ff5\uff0c\u63a5\u4e0b\u4f86\u5c07\u4ecb\u7d39\u4e00\u7cfb\u5217\u7684\u64cd\u4f5c\u8207\u65b9\u6cd5\uff0c\u8b93\u4f60\u66f4\u719f\u6089 List\u3002

    "},{"location":"fundamental/python/lists/#operations","title":"Operations","text":""},{"location":"fundamental/python/lists/#accessing_elements","title":"Accessing elements","text":"

    \u8981\u5b58\u53d6 List \u4e2d\u7684\u5143\u7d20\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u4e2d\u62ec\u865f []\uff0c\u4e26\u5728\u4e2d\u62ec\u865f\u4e2d\u653e\u5165\u5143\u7d20\u7684\u7d22\u5f15\u503c\uff0c\u7d22\u5f15\u503c\u5f9e \\(0\\) \u958b\u59cb\uff0c\u4e26\u4e14\u53ef\u4ee5\u4f7f\u7528\u8ca0\u6578\uff0c\u8ca0\u6578\u7684\u7d22\u5f15\u503c\u662f\u5f9e\u6700\u5f8c\u4e00\u500b\u5143\u7d20\u958b\u59cb\u7b97\u8d77\u3002

    numbers = [1, 2, 3, 4, 5]\n\n# First element\nprint(numbers[0])\n# Last element\nprint(numbers[-1])\nprint(numbers[4])\n
    ouput
    1\n5\n5\n

    \u8b93\u6211\u5011\u914d\u5408\u8ff4\u5708\u4f86\u5370\u51fa\u4e32\u5217\u4e2d\u7684\u5143\u7d20\u3002

    numbers = [1, 2, 3, 4, 5]\n\nfor i in range(len(numbers)):\n    print(numbers[i], end=' ')\n
    ouput
    1 2 3 4 5\n

    len \u9019\u500b\u51fd\u5f0f\u53ef\u4ee5\u53d6\u5f97\u4e32\u5217\u7684\u9577\u5ea6\uff0c\u4e5f\u5c31\u662f\u4e32\u5217\u4e2d\u5143\u7d20\u7684\u500b\u6578\u3002

    \u4e0d\u66c9\u5f97\u4f60\u9084\u8a18\u4e0d\u8a18\u5f97 Repetiton Structures - Foreach \u7684\u5167\u5bb9\uff0c\u6211\u5011\u7528\u9019\u500b\u6982\u5ff5\u4f86\u5370\u51fa\u4e32\u5217\u4e2d\u7684\u5143\u7d20\u3002

    numbers = [1, 2, 3, 4, 5]\n\nfor number in numbers:\n    print(number, end=' ')\n
    ouput
    1 2 3 4 5\n
    "},{"location":"fundamental/python/lists/#slicing","title":"Slicing","text":"

    \u5207\u7247(Slicing)\u53ef\u4ee5\u7528\u4f86\u53d6\u5f97\u4e32\u5217\u4e2d\u7684\u4e00\u90e8\u5206\uff0c\u4f8b\u5982:

    numbers = [1, 2, 3, 4, 5, 6]\n\nprint(numbers[0:4])\nprint(numbers[:4])\nprint(numbers[:-2])\nprint(numbers[1:3])\nprint(numbers[:6:2])\nprint(numbers[::-1])\nprint(numbers[:])\n
    ouput
    [1, 2, 3, 4]\n[1, 2, 3, 4]\n[1, 2, 3, 4]\n[2, 3]\n[1, 3, 5]\n[6, 5, 4, 3, 2, 1]\n[1, 2, 3, 4, 5, 6]\n

    @EditTime : 2024-01-31 21:56

    \u4f60\u5f88\u8070\u660e\uff0c\u61c9\u8a72\u767c\u73fe\u4e86\u7528\u6cd5\u8207 range \u4e00\u6a23\uff0c\u5206\u5225\u662f\u8d77\u59cb\u7d22\u5f15\u503c\u3001\u7d50\u675f\u7d22\u5f15\u503c\u3001\u9593\u9694\uff0c\u5982\u679c\u4e0d\u5beb\u7684\u8a71\uff0c\u9810\u8a2d\u503c\u5206\u5225\u662f \\(0\\)\u3001\u4e32\u5217\u9577\u5ea6\u3001\\(1\\)\u3002

    "},{"location":"fundamental/python/lists/#modifying_elements","title":"Modifying elements","text":"

    \u8981\u4fee\u6539\u4e32\u5217\u4e2d\u7684\u5143\u7d20\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u4e2d\u62ec\u865f []\uff0c\u4e26\u5728\u4e2d\u62ec\u865f\u4e2d\u653e\u5165\u5143\u7d20\u7684\u7d22\u5f15\u503c\uff0c\u7136\u5f8c\u518d\u6307\u5b9a\u65b0\u7684\u503c\u3002

    music_info = [\"Time_To_Pretend\", \"Lazer Boomerang\", \" 2019/4/26\", 1, False]\nmusic_info[0] = \"Time To Pretend\"\nmusic_info[3] = 2\nmusic_info[-1] = True\nprint(music_info)\n
    ouput
    ['Time To Pretend', 'Lazer Boomerang', ' 2019/4/26', 2, True]\n

    Lazer Boomerang - Time To Pretend (Official Audio)

    \u6211\u5011\u53ef\u4ee5\u4fee\u6539\u4e32\u5217\u4e2d\u7684\u503c\uff0c\u9019\u7a31\u70ba \u53ef\u8b8a\u52d5\u7684(mutable)\uff0c\u800c\u5b57\u4e32\u5247\u4e0d\u884c\uff0c\u9019\u7a31\u70ba \u4e0d\u53ef\u8b8a\u52d5\u7684(immutable)\u3002

    sad_cat = \"\ud83d\ude3f\"\nsad_cat[0] = \"\ud83d\ude38\"\n
    ouput
    TypeError: 'str' object does not support item assignment\n
    "},{"location":"fundamental/python/lists/#checking_elements","title":"Checking elements","text":"

    \u8981\u6aa2\u67e5\u4e32\u5217\u4e2d\u662f\u5426\u6709\u67d0\u500b\u5143\u7d20\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 in \u9019\u500b\u904b\u7b97\u5b50\u3002

    numbers = [1, 2, 3, 4, 5]\nprint(1 in numbers)\nprint(6 not in numbers)\n
    ouput
    True\nTrue\n

    Question

    \u5c0d\u65bc\u9577\u5ea6\u70ba \\(n\\) \u7684\u7121\u5e8f\u4e32\u5217\uff0c\u8981\u6aa2\u67e5\u67d0\u500b\u5143\u7d20\u662f\u5426\u5b58\u5728\u65bc\u4e32\u5217\u4e2d\uff0c\u6700\u58de\u7684\u60c5\u6cc1\u4e0b\uff0c\u9700\u8981\u6aa2\u67e5\u591a\u5c11\u6b21?

    \u7b54\u6848\u662f \\(n\\) \u6b21\u5594\uff0c\u56e0\u70ba\u4e00\u500b\u4e00\u500b\u627e\uff0c\u76f4\u5230\u627e\u5230\u6216\u662f\u627e\u5b8c\u70ba\u6b62\uff0c\u50cf\u662f\u4f8b\u5b50\u4e2d\u7684 6\u3002

    \u5728\u6f14\u7b97\u6cd5(Algorithm)\u7684\u7ae0\u7bc0\u4e2d\u6703\u63d0\u5230\u6642\u9593\u8907\u96dc\u5ea6(Time Complexity)\u9019\u500b\u89c0\u5ff5\uff0c\u9019\u88e1\u5c31\u5148\u7d66\u4f60\u4e00\u500b\u5370\u8c61\u5c31\u597d\u4e86~

    "},{"location":"fundamental/python/lists/#methods","title":"Methods","text":"

    \u4f86\u4ecb\u7d39\u4e00\u4e9b\u5e38\u7528\u7684\u4e32\u5217\u65b9\u6cd5\u3002

    "},{"location":"fundamental/python/lists/#append","title":"append","text":"

    append \u9019\u500b\u65b9\u6cd5\u53ef\u4ee5\u5728\u4e32\u5217\u7684\u6700\u5f8c\u9762\u65b0\u589e\u4e00\u500b\u5143\u7d20\u3002

    numbers = [1, 2, 3, 4, 5]\nnumbers.append(6)\nprint(numbers)\nnumbers.append([7, 8, 9])\nprint(numbers)\n
    ouput
    [1, 2, 3, 4, 5, 6]\n[1, 2, 3, 4, 5, 6, [7, 8, 9]]\n

    \u5e0c\u671b\u7b2c\u4e8c\u500b append \u6c92\u6709\u5687\u5230\u4f60\uff0c\u5b83\u53ef\u4ee5\u65b0\u589e\u4e00\u500b\u4e32\u5217\uff0c\u4f46\u662f\u9019\u500b\u4e32\u5217\u6703\u8b8a\u6210\u4e32\u5217\u4e2d\u7684\u4e00\u500b\u5143\u7d20\u3002\u5982\u679c\u4f60\u662f\u60f3\u8981\u628a 7\u30018\u30019 \u9019\u4e09\u500b\u5143\u7d20\u52a0\u5230\u4e32\u5217\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 extend \u9019\u500b\u65b9\u6cd5\u3002

    "},{"location":"fundamental/python/lists/#extend","title":"extend","text":"

    extend \u9019\u500b\u65b9\u6cd5\u53ef\u4ee5\u5728\u4e32\u5217\u7684\u6700\u5f8c\u9762\u65b0\u589e\u53e6\u4e00\u500b\u4e32\u5217\u4e2d\u7684\u5143\u7d20\u3002

    numbers = [1, 2, 3, 4, 5]\nnumbers.extend([6, 7, 8])\nprint(numbers)\n
    ouput
    [1, 2, 3, 4, 5, 6, 7, 8]\n
    "},{"location":"fundamental/python/lists/#pop","title":"pop","text":"

    pop \u9019\u500b\u65b9\u6cd5\u53ef\u4ee5\u79fb\u9664\u4e32\u5217\u4e2d\u7684\u5143\u7d20\uff0c\u4e26\u56de\u50b3\u88ab\u79fb\u9664\u7684\u5143\u7d20\u3002

    fruits = [\"apple\", \"banana\", \"cherry\", \"durian\", \"elderberry\"]\nprint(fruits.pop())\nprint(fruits)\nprint(fruits.pop(1))\nprint(fruits)\n
    ouput
    elderberry\n['apple', 'banana', 'cherry', 'durian']\nbanana\n['apple', 'cherry', 'durian']\n

    \u901a\u5e38\uff0c\u6211\u5011\u6703\u4f7f\u7528 pop \u4f86\u79fb\u9664\u4e32\u5217\u4e2d\u7684\u6700\u5f8c\u4e00\u500b\u5143\u7d20\uff0c\u56e0\u70ba\u9019\u6a23\u53ef\u4ee5\u907f\u514d\u7d22\u5f15\u503c\u8d85\u51fa\u7bc4\u570d\u7684\u932f\u8aa4\uff0c\u4f60\u4e5f\u53ef\u4ee5\u6307\u5b9a\u7d22\u5f15\u503c\uff0c\u4f86\u79fb\u9664\u4e32\u5217\u4e2d\u7684\u5143\u7d20\uff0c\u4f46\u4e0d\u5efa\u8b70\u3002

    "},{"location":"fundamental/python/lists/#clear","title":"clear","text":"

    clear \u9019\u500b\u65b9\u6cd5\u53ef\u4ee5\u79fb\u9664\u4e32\u5217\u4e2d\u7684\u6240\u6709\u5143\u7d20\u3002

    numbers = [1, 2, 3, 4, 5]\nnumbers.clear()\nprint(numbers)\n
    ouput
    []\n
    "},{"location":"fundamental/python/lists/#reverse","title":"reverse","text":"

    reverse \u9019\u500b\u65b9\u6cd5\u53ef\u4ee5\u53cd\u8f49\u4e32\u5217\u3002

    numbers = [1, 2, 3, 4, 5]\nnumbers.reverse()\nprint(numbers)\n
    ouput
    [5, 4, 3, 2, 1]\n
    "},{"location":"fundamental/python/lists/#sort","title":"sort","text":"

    sort \u9019\u500b\u65b9\u6cd5\u53ef\u4ee5\u6392\u5e8f\u4e32\u5217\uff0c\u9810\u8a2d\u662f\u7531\u5c0f\u5230\u5927\u6392\u5e8f\uff0c\u5982\u679c\u8981\u7531\u5927\u5230\u5c0f\u6392\u5e8f\uff0c\u53ef\u4ee5\u6307\u5b9a reverse=True\u3002

    numbers = [5, 4, 3, 2, 1]\nnumbers.sort()\nprint(numbers)\nnumbers.sort(reverse=True)\nprint(numbers)\n
    ouput
    [1, 2, 3, 4, 5]\n[5, 4, 3, 2, 1]\n

    \u751a\u81f3\u4f60\u53ef\u4ee5\u8a2d\u5b9a key\uff0c\u4f86\u6c7a\u5b9a\u6392\u5e8f\u7684\u4f9d\u64da\uff0c\u4f8b\u5982: key=len\uff0c\u5c31\u662f\u6839\u64da\u5143\u7d20 x \u7684 len(x) \u4f86\u6392\u5e8f\u3002

    fruits = [\"apple\", \"banana\", \"watermelon\", \"pineapple\"]\nfruits.sort(key=len)\nprint(fruits)\n
    ouput
    ['apple', 'banana', 'pineapple', 'watermelon']\n
    "},{"location":"fundamental/python/lists/#copy","title":"copy","text":"

    copy \u9019\u500b\u65b9\u6cd5\u56de\u50b3\u4e00\u500b\u6dfa\u8907\u88fd(Shallow Copy)\u7684\u4e32\u5217\u3002

    numbers = [1, 2, 3, 4, 5]\nnumbers_copy = numbers.copy()\nprint(numbers_copy)\nprint(numbers)\n\nprint(\"After changing numbers[1]\")\n\nnumbers[1] = 10\nprint(numbers_copy)\nprint(numbers)\n
    ouput
    [1, 2, 3, 4, 5]\n[1, 2, 3, 4, 5]\nAfter changing numbers[1]\n[1, 2, 3, 4, 5]\n[1, 10, 3, 4, 5]\n

    \u9019\u500b\u4f8b\u5b50\u9084\u4e0d\u80fd\u770b\u51fa\u6dfa\u8907\u88fd\uff0c\u4fee\u6539\u4e86 numbers \u7684\u7b2c\u4e8c\u500b\u5143\u7d20\uff0cnumbers_copy \u4e0d\u6703\u8ddf\u8457\u6539\u8b8a\u3002

    numbers = [1, [2, 3], 4, 5]\nnumbers_copy = numbers.copy()\nprint(numbers_copy)\nprint(numbers)\n\nprint(\"After changing numbers[1]\")\n\nnumbers[1][0] = 6\nprint(numbers_copy)\nprint(numbers)\n
    ouput
    [1, [2, 3], 4, 5]\n[1, [2, 3], 4, 5]\nAfter changing numbers[1]\n[1, [6, 3], 4, 5]\n[1, [6, 3], 4, 5]\n

    \u90a3\u4ec0\u9ebc\u53c8\u662f\u6df1\u8907\u88fd(Deep Copy)\u5462? \u9019\u500b\u5c31\u8981\u7b49\u5230\u6211\u5011\u5b78\u5230\u7269\u4ef6\u5c0e\u5411\u7a0b\u5f0f\u8a2d\u8a08(Object-Oriented Programming)\u7684\u6642\u5019\uff0c\u518d\u4f86\u8ddf\u4f60\u4ecb\u7d39\uff0c\u6211\u4e0d\u61c9\u8a72\u6316\u5751\u7684\u3002

    \u9084\u6709\u66f4\u591a\u65b9\u6cd5\uff0c\u4f60\u53ef\u4ee5\u53c3\u8003 Python Documentation - List\uff0c\u4f46\u6211\u4e0a\u9762\u4ecb\u7d39\u7684\u65b9\u6cd5\uff0c\u4f60\u81f3\u5c11\u8981\u6703\uff0c\u4f60\u4e5f\u8981\u990a\u6210\u770b\u5b98\u65b9\u6587\u4ef6\u7684\u7fd2\u6163\u3002

    "},{"location":"fundamental/python/lists/#list_comprehension","title":"List Comprehension","text":"

    \u4e32\u5217\u7d9c\u5408\u904b\u7b97(List comprehension)\u8b93\u4f60\u7528\u4e00\u884c\u7a0b\u5f0f\u78bc\uff0c\u5c31\u53ef\u4ee5\u5efa\u7acb\u51fa\u64c1\u6709\u67d0\u9805\u6027\u8cea\u5143\u7d20\u7684\u4e32\u5217\u3002

    \u8209\u500b\u4f8b\u5b50\uff0c\u8f38\u5165\u4e00\u500b\u4e32\u5217 a\uff0c\u8f38\u51fa\u4e00\u500b\u4e32\u5217 b\uff0c\u5176\u4e2d b[i] = a[i] ** 2\uff0c\u4e5f\u5c31\u662f b \u4e2d\u7684\u5143\u7d20\u90fd\u662f\u5c0d\u61c9 a \u5143\u7d20\u7684\u5e73\u65b9\u3002

    \u6211\u5011\u5148\u4f7f\u7528\u8ff4\u5708\u4f86\u5be6\u4f5c:

    a = [1, 2, 3, 4, 5]\nb = []\n\nfor num in a:\n    b.append(num ** 2)\n\nprint(b)\n
    ouput
    [1, 4, 9, 16, 25]\n

    \u518d\u4f86\u4f7f\u7528\u4e32\u5217\u7d9c\u5408\u904b\u7b97:

    a = [1, 2, 3, 4, 5]\nb = [num ** 2 for num in a]\n\nprint(b)\n
    ouput
    [1, 4, 9, 16, 25]\n

    \u975e\u5e38\u5730\u512a\u96c5\uff0c\u6211\u5011\u518d\u4f86\u770b\u4e00\u500b\u4f8b\u5b50\uff0c\u8f38\u5165\u4e00\u500b\u4e32\u5217 a\uff0c\u8f38\u51fa\u4e00\u500b\u4e32\u5217 b\uff0c\u5176\u4e2d b \u7684\u5143\u7d20\u90fd\u662f a \u5143\u7d20\u4e2d\u7684\u5076\u6578\u3002

    a = [1, 2, 3, 4, 5]\nb = [num for num in a if num % 2 == 0]\n\nprint(b)\n
    ouput
    [2, 4]\n

    \u9084\u8a18\u5f97 Operators - Bonus: map for input \u63d0\u5230\u7684 map \u55ce?

    \u5148\u4f86\u8907\u7fd2\u4e00\u4e0b\uff0cmap \u53ef\u4ee5\u5c07\u4e00\u500b\u51fd\u5f0f\u5957\u7528\u5230\u4e00\u500b\u5e8f\u5217\u7684\u6bcf\u4e00\u500b\u5143\u7d20\uff0c\u4e26\u56de\u50b3\u4e00\u500b map \u7269\u4ef6\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 list \u5c07 map \u7269\u4ef6\u8f49\u63db\u6210\u4e32\u5217\u3002

    a = [\"1\", \"2\", \"3\", \"4\", \"5\"]\nb = map(int, a)\nprint(type(b))\n\nc = list(b)\nprint(c)\n
    ouput
    <class 'map'>\n[1, 2, 3, 4, 5]\n

    @EditTime : 2024-02-01 23:21

    \u90a3\u80fd\u4e0d\u80fd\u7528\u4e32\u5217\u7d9c\u5408\u904b\u7b97\u4f86\u5be6\u4f5c\u5462?

    a = [\"1\", \"2\", \"3\", \"4\", \"5\"]\nb = [int(num) for num in a]\nprint(b)\n
    ouput
    [1, 2, 3, 4, 5]\n

    \u7b54\u6848\u662f\u80af\u5b9a\u7684\u3002

    \u9084\u6709\u5f88\u591a\u61c9\u7528\uff0c\u4f8b\u5982: \u4e32\u5217\u4e2d\u7684\u5143\u7d20\u90fd\u662f\u5c0f\u5beb\uff0c\u6211\u5011\u60f3\u8981\u628a\u5b83\u5011\u8f49\u63db\u6210\u5927\u5beb\u3002

    lowercase = [\"a\", \"b\", \"c\", \"d\", \"e\"]\nuppercase = [letter.upper() for letter in lowercase]\nprint(uppercase)\n
    ouput
    ['A', 'B', 'C', 'D', 'E']\n

    \u6ce8\u610f\u56c9\uff0c\u9019\u908a\u7528\u5230\u7684\u662f\u65b9\u6cd5\u5594\u3002

    "},{"location":"fundamental/python/lists/#nested_lists","title":"Nested Lists","text":"

    \u5de2\u72c0\u4e32\u5217(Nested Lists)\uff0c\u5c31\u662f\u4e32\u5217\u4e2d\u7684\u5143\u7d20\u4e5f\u662f\u4e32\u5217\u3002

    "},{"location":"fundamental/python/lists/#2d","title":"2D","text":"

    \u5148\u4f86\u8209\u4e00\u500b\u4f60\u53ef\u80fd\u807d\u904e\u7684\u540d\u8a5e\uff0c\u4e8c\u7dad\u9663\u5217(2D Array)\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u5de2\u72c0\u4e32\u5217\u4f86\u5be6\u4f5c\u4e8c\u7dad\u9663\u5217\uff0c\u4f8b\u5982\u5169\u500b \\(3 \\times 3\\) \u7684\u4e8c\u7dad\u9663\u5217\uff0c\u4f86\u9032\u884c\u77e9\u9663\u52a0\u6cd5\u3002

    matrix_1 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]\nmatrix_2 = [[9, 8, 7], [6, 5, 4], [3, 2, 1]]\n\nmatrix_3 = [[0 for i in range(3)] for j in range(3)]\n\nfor i in range(3):\n    for j in range(3):\n        matrix_3[i][j] = matrix_1[i][j] + matrix_2[i][j]\n\nprint(matrix_3)\n
    ouput
    [[10, 10, 10], [10, 10, 10], [10, 10, 10]]\n

    \u6211\u5e0c\u671b matrix_3 \u7684\u521d\u59cb\u5316\u6c92\u6709\u5687\u5230\u4f60\uff0c\u8acb\u4f60\u628a [0 for i in range(3)] \u7576\u6210\u4e00\u500b\u6574\u9ad4 E\uff0c\u518d\u628a [E for j in range(3)] \u7576\u6210\u4e00\u500b\u6574\u9ad4\uff0c\u9019\u6a23\u5c31\u4e0d\u6703\u89ba\u5f97\u5f88\u8907\u96dc\u4e86\uff0ci, j \u90fd\u53ea\u662f\u8a08\u6578\u7528\u7684\u800c\u5df2\uff0c\u4e0d\u8981\u88ab\u5b83\u5011\u5687\u5230\u3002

    "},{"location":"fundamental/python/lists/#jagged","title":"Jagged","text":"

    \u92f8\u9f52\u72c0\u4e32\u5217(Jagged Lists)\uff0c\u5c31\u662f\u5141\u8a31\u5de2\u72c0\u4e32\u5217\u4e2d\u7684\u5143\u7d20\u7684\u9577\u5ea6\u4e0d\u4e00\u6a23\u3002

    \u984c\u5916\u8a71\uff0c\u4e4b\u524d\u5728\u5b78 C \u7684\u6642\u5019\uff0c\u53ea\u80fd\u7528\u6307\u6a19\u4f86\u5be6\u4f5c\uff0c\u4f46\u7528\u8d77\u4f86\u771f\u7684\u5f88\u9ebb\u7169\u3002

    jagged = [[1, 2, 3], [4, 5], [6, 7, 8, 9]]\n\nfor row in jagged:\n    for elem in row:\n        print(elem, end=' ')\n    print()\n
    ouput
    1 2 3 \n4 5 \n6 7 8 9 \n

    \u5e0c\u671b\u9019\u500b\u8ff4\u5708\u7684\u5beb\u6cd5\u4e0d\u6703\u5687\u5230\u4f60\uff0crow \u662f jagged \u4e2d\u7684\u4e00\u500b\u5143\u7d20\uff0c\u4e5f\u5c31\u662f\u4e00\u500b\u4e32\u5217\uff0celem \u662f row \u4e2d\u7684\u4e00\u500b\u5143\u7d20\uff0c\u4e5f\u5c31\u662f\u4e00\u500b\u6574\u6578\u3002

    Python \u7684\u8a9e\u6cd5\u771f\u7684\u5f88\u9748\u6d3b\uff0c\u4f46\u4e5f\u8981\u5f88\u5c0f\u5fc3\uff0c\u4ed6\u63d0\u4f9b\u4e86\u5f88\u591a\u5de5\u5177\uff0c\u4f46\u5982\u679c\u4f60\u4e0d\u6e05\u695a\u4ed6\u662f\u600e\u9ebc\u904b\u4f5c\u7684\uff0c\u5c31\u6703\u5bb9\u6613\u6703\u5beb\u51fa\u6548\u7387\u4f4e\u4e0b\u7684\u7a0b\u5f0f\u78bc\uff0c\u9019\u4e5f\u662f\u96d9\u9762\u5203\uff0c\u6240\u4ee5\u8981\u591a\u591a\u7df4\u7fd2\uff0c\u591a\u591a\u601d\u8003\uff0c\u4f60\u53ef\u4ee5\u7684\u3002

    "},{"location":"fundamental/python/lists/#practice","title":"Practice","text":"

    Itsa - [C_MM33-\u6613] \u627e1~N\u7684\u5b8c\u7f8e\u6578

    Reference code

    table = []\nfor i in range(6, 2 ** 13, 2):\n    s = 0\n    for j in range(1, i):\n        if i % j == 0:\n            s += j\n    if s == i:\n        table.append(i)\n\nwhile True:\n    N = int(input())\n    print(' '.join([str(x) for x in table if x <= N]))\n
    \u5efa\u7acb\u4e00\u500b\u4e32\u5217 table\uff0c\u88e1\u9762\u653e\u4e86 \\(6\\) \u5230 \\(2^{13}\\) \u4e4b\u9593\u7684\u5b8c\u7f8e\u6578\uff0c\u63a5\u8457\u8f38\u5165\u4e00\u500b\u6574\u6578 \\(N\\)\uff0c\u8f38\u51fa \\(1\\) \u5230 \\(N\\) \u4e4b\u9593\u7684\u5b8c\u7f8e\u6578\u3002

    \u90a3\u9ebc \\(2^{13}\\) \u662f\u600e\u9ebc\u4f86\u7684?\u311c\uff0c\u6211\u5237\u5f8c\u53f0\u6e2c\u8cc7\u63a8\u6572\u4f86\u7684\u3002

    join \u65b9\u6cd5\u53ef\u4ee5\u5c07\u5b57\u4e32\u4e32\u5217\u4e2d\u7684\u5143\u7d20\u7528\u6307\u5b9a\u7684\u5b57\u4e32\u9023\u63a5\u8d77\u4f86\uff0c\u9019\u908a\u7528\u7a7a\u767d\u5b57\u4e32 ' ' \u4f86\u9023\u63a5\u3002

    \u9019\u7a2e\u6280\u5de7\u7a31\u70ba\u300c\u5efa\u8868\u300d\uff0c\u4e8b\u5be6\u4e0a\u5b8c\u7f8e\u6578\u5f88\u758f\u6563\uff0c\u4f60\u751a\u81f3\u53ef\u4ee5\u81ea\u5df1\u5efa\u5b8c\u8868\u5f8c\u76f4\u63a5\u5beb\u6b7b\uff0c\u4f46\u9019\u6a23\u7684\u8a71\uff0c\u7a0b\u5f0f\u78bc\u5c31\u4e0d\u5177\u6709\u901a\u7528\u6027\u3002

    table = [6, 28, 496, 8128]\n\nN = int(input())\nprint(' '.join(str(x) for x in table if x <= N))\n

    \u5982\u679c\u5c31\u55ae\u7d14\u89e3\u984c\u7684\u8a71\uff0c\u9019\u6a23\u4e5f\u662f\u53ef\u4ee5\u7684\u3002

    \u6b63\u898f\u7684\u984c\u76ee\u90fd\u6703\u898f\u7bc4\u6e2c\u8cc7\u7bc4\u570d\uff0c\u5982\u679c\u4f60\u4ee5\u5f8c\u4e0a\u5927\u5b78\u5f8c\u9047\u5230\u4e0d\u592a\u9748\u5149\u7684\u52a9\u6559\u6c92\u6709\u6a19\u6e2c\u8cc7\u7bc4\u570d\uff0c\u8a18\u5f97\u96fb\u6b7b\u4ed6\u5011\u3002

    Itsa - [C_MM44-\u6613] The Numbers

    Reference code
    N, M = input().split()\n\ncnt = 0\nfor i in range(0, 6):\n    if M[i] == N[0] and M[i + 1] == N[1]:\n        cnt += 1\n\nprint(cnt)\n

    \u5b57\u4e32\u4e5f\u53ef\u4ee5\u50cf\u662f\u4e32\u5217\u4e00\u6a23\uff0c\u4f7f\u7528\u7d22\u5f15\u503c\u4f86\u5b58\u53d6\u5143\u7d20\u3002

    Itsa - [C_AR01-\u6613] \u4e00\u7dad\u9663\u5217\u53cd\u8f49 I

    Reference code
    arr = input().split()\nprint(' '.join(arr[::-1]))\n

    arr.reverse() \u4e5f\u884c\uff0c\u4f46\u662f\u9019\u6a23\u6703\u6539\u8b8a\u539f\u672c\u7684\u4e32\u5217\uff0c\u5982\u679c\u4f60\u4e0d\u60f3\u6539\u8b8a\u539f\u672c\u7684\u4e32\u5217\uff0c\u5c31\u4f7f\u7528 arr[::-1]\u3002

    arr = input().split()\narr.reverse()\nprint(' '.join(arr))\n

    Itsa - [C_AR03-\u6613] \u8a08\u7b97\u9663\u5217\u4e2d\u6240\u6709\u5143\u7d20\u7684\u7acb\u65b9\u548c

    Reference code
    arr = map(int, input().split())\nans = 0\n\nfor num in arr:\n    ans += num ** 3\n\nprint(ans)\n

    \u6211\u4e26\u6c92\u6709\u628a map \u7269\u4ef6\u8f49\u63db\u6210\u4e32\u5217\uff0c\u56e0\u70ba\u6211\u53ea\u9700\u8981\u4e00\u6b21\u8fed\u4ee3\uff0c\u6240\u4ee5\u76f4\u63a5\u7528 map \u7269\u4ef6\u5c31\u597d\u3002

    \u4f86\u770b\u4e00\u884c\u89e3:

    print(sum(int(x) ** 3 for x in input().split()))\n

    \u53c3\u8003\u5c31\u597d\u3002

    Itsa - [C_AR09-\u6613] \u5169\u6578\u5dee\u503c

    Reference code
    arr1 = list(map(int, input().split(',')))\narr1.sort()\narr2 = arr1.copy()\narr2.sort(reverse=True)\n\nmax_num,min_num  = 0, 0\nfor i in range(len(arr1) - 1, -1, -1):\n    # convert list to number\n    max_num = max_num * 10 + arr1[i]\n    min_num = min_num * 10 + arr2[i]\n\nprint(max_num - min_num)\n

    \u4e0d\u61c2\u6392\u5e8f\u6c92\u95dc\u4fc2\uff0c\u6211\u5011\u5148\u77e5\u9053\u600e\u9ebc\u7528\u5c31\u597d\uff0c\u4ee5\u5f8c\u6211\u6703\u6559\u4f60\u539f\u7406\u3002

    \u800c\u9019\u984c\u7684\u91cd\u9ede\u662f\uff0c\u5982\u4f55\u5c07\u4e32\u5217\u8f49\u63db\u6210\u6578\u5b57\u3002\u5f9e\u500b\u4f4d\u6578\u958b\u59cb\uff0c\u6bcf\u6b21\u4e58 \\(10\\)\uff0c\u518d\u52a0\u4e0a\u4e0b\u4e00\u500b\u6578\u5b57\u3002

    Itsa - [C_AR022-\u6613] \u5b57\u6bcd\u51fa\u73fe\u7684\u983b\u7387

    Reference code
    string = input()\n\nfreq = [0] * 26\n\nfor c in string:\n    if c.isalpha():\n        freq[ord(c.lower()) - ord('a')] += 1\n\nprint(' '.join(str(x) for x in freq))\n

    \u9019\u984c\u9700\u8981\u4e00\u500b\u5148\u5099\u77e5\u8b58\uff0cASCII \u78bc\uff0cord \u51fd\u5f0f\u53ef\u4ee5\u53d6\u5f97\u5b57\u5143\u7684 ASCII \u78bc\u3002

    \u518d\u5229\u7528 isalpha \u65b9\u6cd5\uff0c\u4f86\u5224\u65b7\u5b57\u5143\u662f\u5426\u70ba\u5b57\u6bcd\uff0c\u4ee5\u53ca lower \u65b9\u6cd5\uff0c\u4f86\u5c07\u5b57\u6bcd\u8f49\u63db\u6210\u5c0f\u5beb\uff0c\u9019\u6a23\u5c31\u53ef\u4ee5\u5c07\u5b57\u6bcd\u6620\u5c04\u5230 0 \u5230 25 \u4e4b\u9593\u3002

    \u95dc\u65bc\u5b57\u4e32\u7684\u4e3b\u984c\uff0c\u5f8c\u9762\u6703\u518d\u8ddf\u4f60\u4ecb\u7d39\u3002

    Itsa - [C_AR025-\u6613] \u8a08\u7b97ASCII\u5b57\u5143

    Reference code
    string = input()\n\nfreq = [0] * 128\n\n\nfor i in range(len(string)):\n    freq[ord(string[i])] += 1\n\nfor i in range(len(freq) - 1, -1, -1):\n    if freq[i] > 0:\n        print(f'{i} {freq[i]}')\n

    \u9019\u984c\u8ddf\u4e0a\u4e00\u984c\u5f88\u50cf\u3002

    Itsa - [C_AR029-\u96e3] \u6587\u5b57\u7de8\u78bc

    Reference code
    plain_text = input()\n\nN = len(plain_text)\nM = 1\nwhile M * M < N:\n    M += 1\n\narr = [[' ' for _ in range(M)] for _ in range(M)]\n\nfor i in range(N):\n    arr[i // M][i % M] = plain_text[i]\n\ncipher_text = []\nfor i in range(M):\n    for j in range(M):\n        cipher_text.append(arr[j][i])\n\nprint(''.join(cipher_text))\n

    \u77e9\u9663\u8f49\u7f6e\uff0c\u6240\u4ee5 arr[j][i] \u8b8a\u6210 arr[i][j]\u3002

    "},{"location":"fundamental/python/lists/#assignment","title":"Assignment","text":"

    Itsa - [C_MM42-\u4e2d] \u6c42(-1)^(n+1)x[1/(2n-1)]\u7684\u548c

    Itsa - [C_AR02-\u6613] \u4e00\u7dad\u9663\u5217\u53cd\u8f49 II

    Itsa - [C_AR10-\u4e2d] \u65b0\u901a\u8a71\u8cbb\u7387

    Itsa - [C_AR021-\u6613] \u6210\u7e3e\u7d71\u8a08

    Itsa - [C_AR023-\u6613] \u5b57\u6839\u8207\u5b50\u5b57\u4e32

    Itsa - [C_AR031-\u4e2d] \u4e00\u7dad\u77e9\u9663\u8868\u793a\u4e8c\u7dad\u5e73\u9762\u7a7a\u9593

    Itsa - [C_AR33-\u6613] \u8f49\u7f6e\u77e9\u9663

    Itsa - [C_AR34-\u6613] \u8eab\u5206\u8b49\u9a57\u8b49\u5668

    Itsa - [C_AR35-\u6613] \u751f\u8096\u554f\u984c

    Itsa - [C_AR41-\u6613] \u4e00\u6574\u6578\u5e8f\u5217\u6240\u542b\u4e4b\u6574\u6578\u500b\u6578\u53ca\u5e73\u5747\u503c

    Itsa - [C_AR46-\u6613] \u9663\u5217\u5e73\u65b9\u548c\u554f\u984c

    Itsa - [C_AR48-\u6613] \u6578\u5b57\u52a0\u5bc6

    @EditTime : 2024-02-03 21:30

    "},{"location":"fundamental/python/operators/","title":"Operators","text":""},{"location":"fundamental/python/operators/#introduction","title":"Introduction","text":"

    \u5728\u9019\u500b\u7ae0\u7bc0\u4e2d\uff0c\u6211\u5011\u8981\u4f86\u5b78\u7fd2\u904b\u7b97\u5b50\uff0c\u904b\u7b97\u5b50\u53ef\u4ee5\u8b93\u6211\u5011\u5c0d\u8b8a\u6578\u505a\u904b\u7b97\uff0c\u4f8b\u5982: \u52a0\u6cd5\u3001\u6e1b\u6cd5\u3001\u4e58\u6cd5\u3001\u9664\u6cd5\u7b49\u7b49\u3002

    "},{"location":"fundamental/python/operators/#arithmetic_operators","title":"Arithmetic Operators","text":"

    \u9996\u5148\uff0c\u6211\u5011\u4f86\u770b\u770b\u7b97\u8853\u904b\u7b97\u5b50\uff0c\u6211\u5011\u719f\u6089\u7684\u56db\u5247\u904b\u7b97\u5c31\u662f\u7b97\u8853\u904b\u7b97\u5b50\uff0c\u4ed6\u5011\u5206\u5225\u662f +\u3001-\u3001*\u3001/\uff0c\u5206\u5225\u4ee3\u8868\u52a0\u6cd5\u3001\u6e1b\u6cd5\u3001\u4e58\u6cd5\u3001\u9664\u6cd5\u3002

    x, y = 10, 3\nprint(x + y)\nprint(x - y)\nprint(x * y)\nprint(x / y)\nz = x // y\nprint(z)\nprint(type(z))\nprint(x % y)\nprint(x ** y)\n
    ouput
    13\n7\n30\n3.3333333333333335\n3\n<class 'int'>\n1\n1000\n

    \u6211\u76f8\u4fe1\u770b\u5b8c\u8f38\u51fa\u5f8c\uff0c\u4f60\u80fd\u5927\u81f4\u660e\u77ad\u5404\u500b\u904b\u7b97\u5b50\u7684\u4f5c\u7528\uff0c\u5176\u4e2d\u60f3\u8acb\u4f60\u7559\u610f * \u4e58\u6cd5\u904b\u7b97\u5b50\uff0c\u8acb\u4f60\u4e0d\u8981\u6253\u6210 x\uff0c\u4ee5\u53ca / \u8207 // \u7684\u5dee\u5225\uff0c\u5f8c\u8005\u6703\u5c07\u7d50\u679c\u5411\u4e0b\u53d6\u6574\u3002\u9084\u6709\u6bd4\u8f03\u7279\u5225\u7684 % \uff0c\u7559\u610f\u5230 10 = 3 * 3 + 1\uff0c\u5c31\u662f\u53d6\u9918\u6578\uff1b\u800c\u770b\u8d77\u4f86\u6700\u5947\u7279\u7684 ** \uff0c\u4ed6\u7684\u4f5c\u7528\u662f\u6c42\u51aa\u3002

    \u6211\u5011\u4f86\u8907\u7fd2\u4e00\u4e0b\u570b\u5c0f\u6578\u5b78:

    # Upper case for constant\nPI = 3.14\nr = 2\narea = PI * (r ** 2)\nperimeter = 2 * PI * r\nprint(f'Area: {area}, Perimeter: {perimeter}')\n\n# Sum of 1 to 100\ntotal = (1 + 100) * 100 // 2\nprint(f'The sum of 1 to 100 is {total}')\n

    ouput
    Area: 12.56, Perimeter: 12.56\nThe sum of 1 to 100 is 5050\n

    \u9019\u908a\u8981\u63d0\u9192\u4f60\u7684\u662f\uff0c\u904b\u7b97\u5b50\u4e4b\u9593\u6709\u512a\u5148\u9806\u5e8f\uff0c\u7576\u4f60\u4e0d\u78ba\u5b9a\u7d50\u679c\u7684\u6642\u5019\uff0c\u8acb\u5584\u7528\u62ec\u865f\u3002

    x = 'A' + 'n' + 'i' + 'm' + 'a' + 'l' + 's'\nprint(x)\n
    ouput
    Animals\n

    Martin Garrix - Animals (Official Video)

    \u518d\u8acb\u4f60\u7559\u610f\u4e00\u4ef6\u4e8b\uff0c\u4e0d\u540c\u985e\u5225\u5c0d\u65bc\u904b\u7b97\u5b50\u7684\u4f5c\u7528\u662f\u4e0d\u540c\u7684\uff0c\u4f8b\u5982\u5b57\u4e32\u7684 + \u6703\u5c07\u5169\u500b\u5b57\u4e32\u76f8\u9023\uff0c\u800c\u6574\u6578\u7684 + \u5247\u6703\u5c07\u5169\u500b\u6574\u6578\u76f8\u52a0\u3002

    Question

    1. 2 ** 3 ** 2 \u7684\u7d50\u679c\u662f\u591a\u5c11?
    2. 2 ** (3 ** 2) \u7684\u7d50\u679c\u662f\u591a\u5c11?
    3. (2 ** 3) ** 2 \u7684\u7d50\u679c\u662f\u591a\u5c11?
    "},{"location":"fundamental/python/operators/#comparison_operators","title":"Comparison Operators","text":"

    \u6bd4\u8f03\u904b\u7b97\u5b50\u7684\u7d50\u679c\u6703\u662f True \u6216 False\uff0c\u9019\u500b\u7d50\u679c\u6211\u5011\u7a31\u70ba\u5e03\u6797\u503c\u3002

    \u6211\u5011\u4f86\u4ee5\u76f4\u89d2\u4e09\u89d2\u5f62\u7684\u6027\u8cea\u4f86\u505a\u4e00\u4e9b\u6bd4\u8f03\u904b\u7b97\u5b50\u7684\u7df4\u7fd2\u3002

    a, b, c = 3, 4, 5\n\nprint(a < b)\nprint(a > b)\nprint(a <= b)\nprint(a >= b)\nprint(a ** 2 + b ** 2 == c ** 2)\nprint(a ** 2 + b ** 2 != c ** 2)\nprint((a + b) > c)\n
    ouput
    False\nTrue\nFalse\nTrue\nFalse\nTrue\n

    \u9019\u908a\u8981\u63d0\u9192\u4f60\uff0c == \u662f\u6bd4\u8f03\u904b\u7b97\u5b50\uff0c\u800c = \u662f\u6307\u6d3e\u904b\u7b97\u5b50\uff0c\u4ed6\u5011\u7684\u610f\u601d\u662f\u4e0d\u4e00\u6a23\u7684\u3002

    \u6700\u5f8c\u4f86\u770b\u4e00\u500b\u4f8b\u5b50:

    age = 14\nprint(12 <= age <= 18)\n\nx, y, z = 1, 2, 3\nprint(x < y < z)\nprint(x < y and y < z)\n

    ouput
    True\nTrue\nTrue\n

    \u5728Python\u4e2d\uff0c\u6211\u5011\u53ef\u4ee5\u5c07\u6bd4\u8f03\u904b\u7b97\u5b50\u9023\u63a5\u8d77\u4f86\uff0c\u9019\u6a23\u7684\u5beb\u6cd5\u53ef\u4ee5\u8b93\u6211\u5011\u7684\u7a0b\u5f0f\u78bc\u66f4\u7c21\u6f54\u3002

    Question

    1. print(1 < 2 < 3 < 4 < 5) \u6703\u5370\u51fa\u4ec0\u9ebc?
    2. print(1 < 2 < 3 < 4 > 5) \u6703\u5370\u51fa\u4ec0\u9ebc?
    "},{"location":"fundamental/python/operators/#logical_operators","title":"Logical Operators","text":"

    \u6211\u5011\u7e7c\u7e8c\u5f80\u4e0b\u770b\uff0c\u9019\u908a\u6211\u5011\u8981\u4ecb\u7d39\u908f\u8f2f\u904b\u7b97\u5b50\uff0c\u4ed6\u53ef\u4ee5\u5c07\u591a\u500b\u5e03\u6797\u503c\u7d50\u5408\u6210\u4e00\u500b\u5e03\u6797\u503c\u3002

    has_license = True\nis_drunk = False\nage = 18\n\nprint(f\"Can I drive a car? {has_license and not is_drunk and age >= 18}\")\nprint(not has_license)\nprint(not is_drunk)\nprint(age >= 18 or is_drunk or not has_license)\n
    ouput
    Can I drive a car? True\nFalse\nTrue\nTrue\n

    \u9019\u908a\u8981\u63d0\u9192\u4f60\u7684\u662f\uff0c and \u53ea\u6709\u5728\u6240\u6709\u5e03\u6797\u503c\u90fd\u662f True \u7684\u6642\u5019\uff0c\u7d50\u679c\u624d\u6703\u662f True\uff0c\u800c or \u53ea\u8981\u6709\u4e00\u500b\u5e03\u6797\u503c\u662f True\uff0c\u7d50\u679c\u5c31\u6703\u662f True\u3002

    \u56e0\u6b64\u6709\u6240\u8b02\u7684\u77ed\u8def\u6c42\u503c(Short-circuit Evaluation)\uff0c\u7576 and \u7684\u7b2c\u4e00\u500b\u5e03\u6797\u503c\u662f False\uff0c\u5f8c\u9762\u7684\u5e03\u6797\u503c\u5c31\u4e0d\u6703\u88ab\u8a08\u7b97\uff0c\u56e0\u70ba\u7d50\u679c\u4e00\u5b9a\u662f False\uff1b\u800c or \u7684\u7b2c\u4e00\u500b\u5e03\u6797\u503c\u662f True\uff0c\u5f8c\u9762\u7684\u5e03\u6797\u503c\u5c31\u4e0d\u6703\u88ab\u8a55\u4f30\uff0c\u56e0\u70ba\u7d50\u679c\u4e00\u5b9a\u662f True\u3002

    \u800c not \u662f\u4e00\u5143\u904b\u7b97\u5b50\uff0c\u4ed6\u53ea\u6703\u5c07\u5e03\u6797\u503c\u53cd\u8f49\u3002

    Question

    1. print(not True and False) \u6703\u5370\u51fa\u4ec0\u9ebc?
    2. print(not True or False) \u6703\u5370\u51fa\u4ec0\u9ebc?
    3. print(not True and not False) \u6703\u5370\u51fa\u4ec0\u9ebc?
    4. print(not True or not False) \u6703\u5370\u51fa\u4ec0\u9ebc?
    "},{"location":"fundamental/python/operators/#bitwise_operators","title":"Bitwise Operators","text":"

    \u5728\u9019\u908a\u6211\u5011\u8981\u4ecb\u7d39\u4f4d\u5143\u904b\u7b97\u5b50\uff0c\u4ed6\u662f\u5c0d\u4e8c\u9032\u4f4d\u7684\u904b\u7b97\uff0c\u6211\u5011\u53ef\u4ee5\u7528 bin() \u4f86\u89c0\u5bdf\u4e8c\u9032\u4f4d\u7684\u7d50\u679c\u3002

    a, b = 2, 3\nprint(f\"a={bin(a)}\")\nprint(f\"b={bin(b)}\")\n\nprint(a & b, bin(a & b))\nprint(a | b, bin(a | b))\nprint(a ^ b, bin(a ^ b))\nprint(~a, bin(~a))\n\nprint(a << 1, bin(a << 1))\nprint(a >> 1, bin(a >> 1))\n
    ouput
    a=0b10\nb=0b11\n2 0b10\n3 0b11\n1 0b1\n-3 -0b11\n4 0b100\n1 0b1\n

    & \u662f\u4f4d\u5143\u7684 and\uff0c | \u662f\u4f4d\u5143\u7684 or\uff0c ^ \u662f\u4f4d\u5143\u9593\u7684\u9032\u884c\u4e92\u65a5\u6216\u904b\u7b97\uff0c ~ \u662f\u4f4d\u5143\u7684 not\uff0c << \u662f\u4f4d\u5143\u7684\u5de6\u79fb\uff0c >> \u662f\u4f4d\u5143\u7684\u53f3\u79fb\u3002

    \u5728\u5f80\u4e0b\u4e4b\u524d\uff0c\u8acb\u4f60\u5148\u60f3\u60f3\u6211\u5011\u8a72\u5982\u4f55\u5224\u65b7\u4e00\u500b\u6578\u5b57\u662f\u5947\u6578\u9084\u662f\u5076\u6578\uff0c\u6211\u5011\u53ef\u4ee5\u7528 % \u4f86\u5224\u65b7\uff0c\u4f46\u662f\u6211\u5011\u4e5f\u53ef\u4ee5\u7528\u4f4d\u5143\u904b\u7b97\u4f86\u5224\u65b7\u3002

    a, b = 5678, 4843\nprint(f\"Is a even? {a % 2 == 0}\")\nprint(f\"Is b odd? {b & 1 == 1}\")\n
    ouput
    Is a even? True\nIs b odd? True\n

    Question

    1. \u5982\u4f55\u5224\u65b7\u4e00\u500b\u6578\u5b57\u662f 2 \u7684\u51aa?
    2. \u5982\u4f55\u5f97\u5230\u4e00\u500b\u6578\u5b57\u7684 16 \u500d\uff0c\u4f46\u4e0d\u80fd\u7528 * \u4e58\u6cd5\u904b\u7b97\u5b50?
    "},{"location":"fundamental/python/operators/#assignment_operators","title":"Assignment Operators","text":"

    \u6211\u5011\u5df2\u7d93\u5b78\u6703\u4e86\u4e00\u4e9b\u904b\u7b97\u5b50\uff0c\u73fe\u5728\u6211\u5011\u8981\u4f86\u5b78\u7fd2\u4e00\u4e9b\u6307\u6d3e\u904b\u7b97\u5b50\uff0c\u4ed6\u53ef\u4ee5\u5c07\u904b\u7b97\u7d50\u679c\u6307\u5b9a\u7d66\u8b8a\u6578\u3002

    \u5148\u4f86\u770b\u770b\u4e00\u500b\u7c21\u55ae\u7684\u4f8b\u5b50\uff0c\u6211\u5011\u53ef\u4ee5\u7528 += \u4f86\u5c07\u8b8a\u6578\u52a0\u4e0a\u67d0\u500b\u503c\uff0c\u9019\u500b\u904b\u7b97\u5b50\u53ef\u4ee5\u8b93\u6211\u5011\u7684\u7a0b\u5f0f\u78bc\u66f4\u7c21\u6f54\u3002

    x = 1\nx = x + 2\ny = 1\ny += 2\nprint(x, y)\n
    ouput
    3 3\n

    \u518d\u4f86\u770b\u770b\u5176\u4ed6\u7684\u6307\u6d3e\u904b\u7b97\u5b50\u3002

    x = 1\nx += 2\nprint(x)\nx -= 1\nprint(x)\nx *= 3\nprint(x)\nx //= 2\nprint(x)\nx **= 2\nprint(x)\nx <<= 1\nprint(x)\n
    ouput
    3\n2\n6\n3\n9\n18\n

    \u5c0d\u4e86\uff0c\u8acb\u4f60\u5225\u5fd8\u8a18 = \u4e5f\u662f\u4e00\u500b\u6307\u6d3e\u904b\u7b97\u5b50\u3002

    x = y = z = 1\nprint(x, y, z)\n
    ouput
    1 1 1\n

    \u5e0c\u671b\u9019\u500b\u4f8b\u5b50\u53ef\u4ee5\u8b93\u4f60\u66f4\u719f\u6089\u6307\u6d3e\u904b\u7b97\u5b50\u3002

    Question

    1. \u6709\u6c92\u6709 and= \u9019\u500b\u6307\u6d3e\u904b\u7b97\u5b50?
    2. &= \u9019\u500b\u6307\u6d3e\u904b\u7b97\u5b50\u7684\u4f5c\u7528\u662f\u4ec0\u9ebc?
    "},{"location":"fundamental/python/operators/#bonus_f-string_for_float","title":"Bonus: f-string for float","text":"

    \u70ba\u4e86\u80fd\u8b93\u4f60\u7df4\u7fd2\u4e00\u4e9b\u984c\u76ee\uff0c\u6211\u5148\u5728\u9019\u88e1\u4ecb\u7d39\u5982\u4f55\u5370\u51fa\u6d6e\u9ede\u6578\u5230\u6307\u5b9a\u4f4d\u6578\u3002

    \u5728 Say Hello to Python - Input \u4e2d\uff0c\u6709\u7a0d\u5fae\u63d0\u904e\uff0c\u5982\u679c\u4f60\u5b8c\u5168\u6c92\u5370\u8c61\uff0c\u8acb\u4f60\u56de\u53bb\u8907\u7fd2\u4e00\u4e0b\u3002

    \u7d66\u4f60\u6d6e\u9ede\u6578 x \uff0c\u8acb\u4f60\u5370\u51fa x \u7684\u5e73\u65b9\u6839\u8207\u5e73\u65b9\uff0c\u4e26\u4e14\u53ea\u5370\u51fa\u5c0f\u6578\u9ede\u5f8c\u5169\u4f4d\u3002

    x = 3.1415926\nprint(f\"The square root of {x} is {x ** 0.5:.2f}\")\nprint(f\"The square of {x} is {x ** 2:.2f}\")\n
    ouput
    The square root of 3.1415926 is 1.77\nThe square of 3.1415926 is 9.87\n

    @EditTime : 2024-01-27 11:52

    "},{"location":"fundamental/python/operators/#bonus_map_for_input","title":"Bonus: map for input","text":"

    \u518d\u6b21\u8907\u7fd2 Variable and Input - Mutiple Input \u4e2d\u7684\u4f8b\u5b50\uff0c\u6211\u5011\u53ef\u4ee5\u7528 split() \u4f86\u5c07\u8f38\u5165\u7684\u5b57\u4e32\u5207\u5272\u6210\u591a\u500b\u5b57\u4e32\u3002

    \u4f46\u662f\u5982\u679c\u6211\u5011\u60f3\u8981\u5c07\u9019\u4e9b\u5b57\u4e32\u8f49\u63db\u6210\u6574\u6578\uff0c\u6211\u5011\u53ef\u4ee5\u600e\u9ebc\u505a\u5462?

    a, b, c = input().split()\nprint(int(a) + int(b) + int(c))\n
    input
    1 2 3\n
    ouput
    6\n

    \u96d6\u7136\u9019\u6a23\u5beb\u4e5f\u53ef\u4ee5\uff0c\u4f46\u662f\u5982\u679c\u6211\u5011\u60f3\u8981\u8f38\u5165\u5f88\u591a\u500b\u6578\u5b57\uff0c\u9019\u6a23\u5beb\u5c31\u6703\u5f88\u9ebb\u7169\uff0c\u9019\u6642\u5019\u6211\u5011\u53ef\u4ee5\u7528 map() \u4f86\u5e6b\u52a9\u6211\u5011\u3002

    a, b, c = map(int, input().split())\nprint(a + b + c)\n
    input
    4 5 6\n
    ouput
    15\n

    map(function, iterable) \u6703\u5c07 iterable \u4e2d\u7684\u6bcf\u4e00\u500b\u5143\u7d20\u90fd\u4e1f\u9032 function \u4e2d\uff0c\u5728\u9019\u88e1\u7684 iterable \u662f input().split()\uff0c\u800c function \u662f int\uff0c\u56e0\u6b64 map(int, input().split()) \u6703\u5c07 input().split() \u4e2d\u7684\u6bcf\u4e00\u500b\u5143\u7d20\u90fd\u8f49\u63db\u6210\u6574\u6578\u3002

    \u4f60\u53ef\u4ee5\u5617\u8a66\u5c07\u4f7f\u7528\u5225\u7684\u51fd\u5f0f\uff0c\u4f8b\u5982 float \u6216 str\uff0c\u4f46\u8acb\u4f60\u8a18\u5f97\u4e0d\u8981\u52a0\u4e0a\u62ec\u865f\uff0c\u56e0\u70ba\u6211\u5011\u53ea\u662f\u8981\u5c07\u51fd\u5f0f\u7684\u540d\u7a31\u50b3\u9032\u53bb\uff0c\u800c\u4e0d\u662f\u8981\u57f7\u884c\u51fd\u5f0f\u3002

    \u6211\u5011\u4f7f\u7528 Unpacking \u7684\u65b9\u5f0f\u4f86\u5c07 map() \u7684\u7d50\u679c\u6307\u6d3e\u7d66\u8b8a\u6578\u3002\u6211\u76f8\u4fe1\u4f60\u9084\u8a18\u5f97\u4ec0\u9ebc\u662f Unpacking \u5427?

    \u5982\u679c\u4f60\u4e0d\u592a\u80fd\u7406\u89e3\uff0c\u4e5f\u6c92\u95dc\u4fc2\uff0c\u5148\u5b78\u6703\u600e\u9ebc\u7528\u5c31\u597d\u3002

    "},{"location":"fundamental/python/operators/#practice","title":"Practice","text":"

    \u6709\u4e86\u672c\u7ae0\u7684\u57fa\u790e\u5f8c\uff0c\u5176\u5be6\u5df2\u7d93\u53ef\u4ee5\u505a\u5f88\u591a\u984c\u76ee\u4e86\uff0c\u6211\u5011\u4f86\u505a\u4e00\u4e9b\u7df4\u7fd2\u984c\u5427!

    Itsa - [C_MM01-\u6613] \u8a08\u7b97\u68af\u578b\u9762\u7a4d

    Reference code
    a, b, h = map(int, input().split())\narea = (a + b) * h / 2\nprint(f\"Trapezoid area:{area}\")\n

    Itsa - [C_MM02-\u6613] \u8a08\u7b97\u4e09\u89d2\u5f62\u9762\u7a4d

    Reference code
    a, b = map(int, input().split())\narea = a * b / 2\nprint(area)\n

    Itsa - [C_MM04-\u6613] \u8a08\u7b97\u7e3d\u548c\u3001\u4e58\u7a4d\u3001\u5dee\u3001\u5546\u548c\u9918\u6578

    Reference code
    a, b = map(int, input().split())\n\nprint(f\"{a}+{b}={a + b}\")\nprint(f\"{a}*{b}={a * b}\")\nprint(f\"{a}-{b}={a - b}\")\nprint(f\"{a}/{b}={a // b}...{a % b}\")\n

    Itsa - [C_MM06-\u6613] \u82f1\u54e9\u8f49\u516c\u91cc

    Reference code
    mile = int(input())\nkm = mile * 1.6\nprint(f\"{km:.1f}\")\n
    "},{"location":"fundamental/python/operators/#assignment","title":"Assignment","text":"

    Itsa - [C_MM07-\u6613] \u8a08\u7b97\u5e73\u65b9\u503c\u8207\u7acb\u65b9\u503c

    Itsa - [C_MM08-\u6613] \u8a08\u7b97\u5169\u6578\u548c\u7684\u5e73\u65b9\u503c

    Itsa - [C_MM10-\u6613] \u651d\u6c0f\u6eab\u5ea6\u8f49\u83ef\u5f0f\u6eab\u5ea6

    Itsa - [C_MM11-\u6613] \u8cfc\u7968\u8a08\u7b97

    Itsa - [C_MM12-\u6613] \u76f8\u9047\u6642\u9593\u8a08\u7b97

    Itsa - [C_MM14-\u6613] \u8a08\u7b97\u6642\u9593\u7684\u7d44\u5408

    @EditTime : 2024-01-28 22:03

    "},{"location":"fundamental/python/repetition_structures/","title":"Repetition Structures","text":""},{"location":"fundamental/python/repetition_structures/#introduction","title":"Introduction","text":"

    \u96fb\u8166\u6700\u6703\u505a\u7684\u4e8b\uff0c\u5c31\u662f\u91cd\u8907\u7684\u4e8b\u60c5\uff0c\u6240\u4ee5\u9019\u88e1\u8981\u8ddf\u4f60\u4ecb\u7d39\u8ff4\u5708(Loop)\uff0c\u8ff4\u5708\u53ef\u4ee5\u8b93\u6211\u5011\u91cd\u8907\u57f7\u884c\u4e00\u6bb5\u7a0b\u5f0f\u78bc\uff0c\u800c\u4e0d\u7528\u4e00\u884c\u4e00\u884c\u7684\u5beb\u51fa\u4f86\u3002

    \u5982\u679c\u4f60\u8981\u5370 \\(100\\) \u6b21 Hello World!\uff0c\u4f60\u6703\u600e\u9ebc\u505a\u5462?

    # ...\nprint(\"Hello World!\")\nprint(\"Hello World!\")\nprint(\"Hello World!\")\n

    \u4f60\u6703\u771f\u7684\u5beb \\(100\\) \u884c\u55ce?\u7576\u7136\u4e0d\u6703\uff0c\u4e0d\u7136\u4f60\u6703\u6c23\u6b7b\uff0c\u7136\u5f8c\u628a\u96fb\u8166\u7838\u4e86\u3002

    "},{"location":"fundamental/python/repetition_structures/#for_loop","title":"For Loop","text":"

    \u9996\u5148\uff0c\u6211\u5011\u4f86\u770b\u770b for \u8ff4\u5708\u7684\u7528\u6cd5\u3002\u4e26\u8209\u500b\u7c21\u55ae\u7684\u4f8b\u5b50\uff0c\u5370\u51fa \\(1\\) \u5230 \\(5\\):

    for i in range(1, 6, 1):\n    print(i, end=' ')\n
    ouput
    1 2 3 4 5\n

    Time Loop - Purrple Cat

    range\uff0c\u9019\u500b\u51fd\u5f0f\u53ef\u4ee5\u7522\u751f\u4e00\u500b\u6578\u5217\uff0c\u4e26\u4e14\u53ef\u4ee5\u6307\u5b9a\u8d77\u59cb\u503c\u3001\u7d50\u675f\u503c\u3001\u9593\u9694\u503c\u3002\u9019\u500b\u51fd\u5f0f\u7684\u7528\u6cd5\u5982\u4e0b:

    \u5982\u679c\u53ea\u6709\u4e00\u500b\u53c3\u6578\uff0c\u90a3\u5c31\u662f\u7d50\u675f\u503c\uff0c\u8d77\u59cb\u503c\u9810\u8a2d\u70ba \\(0\\)\uff0c\u9593\u9694\u503c\u9810\u8a2d\u70ba \\(1\\)\u3002

    range(start=0, stop, step=1) \u4e26\u4e14\u6ce8\u610f\uff0cstop \u662f\u4e0d\u5305\u542b\u5728\u6578\u5217\u4e2d\u7684\u3002

    "},{"location":"fundamental/python/repetition_structures/#foreach","title":"Foreach","text":"

    \u8209\u500b\u4f8b\u5b50\uff0c\u6211\u60f3\u628a\u5b57\u4e32 \"Speed_of_Light\" \u4e2d\u7684\u6bcf\u500b\u5b57\u5143\u90fd\u5370\u51fa\u4f86\u3002

    for c in \"Speed_of_Light\":\n    print(c, end=' ')\n

    ouput

    S p e e d _ o f _ L i g h t \n
    DJ OKAWARI feat. \u4e8c\u5bae\u611b \u300cSpeed of Light\u300d

    \u9019\u88e1\u7684\u8ff4\u5708\u66f4\u63a5\u8fd1\u6982\u5ff5\u4e0a\u7684 Foreach\uff0c\u6bcf\u6b21\u8ff4\u5708\u90fd\u6703\u53d6\u51fa\u5b57\u4e32\u4e2d\u7684\u4e00\u500b\u5b57\u5143\uff0c\u4e26\u4e14\u5c07\u4ed6\u653e\u5230 c \u4e2d\uff0c\u9019\u500b\u6982\u5ff5\u8acb\u4f60\u8a18\u8d77\u4f86\u3002

    "},{"location":"fundamental/python/repetition_structures/#break_and_continue","title":"Break and Continue","text":"

    \u518d\u8209\u500b\u4f8b\u5b50\uff0c\u8a08\u7b97 \\(\\sum_{i=1}^n{i}=1+2+\\cdots+n\\)

    n = int(input())\ntotal = 0\n\n# 1 + 2 + ... + n\nfor i in range(n + 1):\n    total += i\n\nprint(total)\n
    input
    100\n
    ouput
    5050\n

    \u63a5\u4e0b\u4f86\uff0c\u8ddf\u4f60\u4ecb\u7d39 break \u8207 continue\uff0c\u9019\u5169\u500b\u95dc\u9375\u5b57\u53ef\u4ee5\u7528\u4f86\u63a7\u5236\u8ff4\u5708\u7684\u57f7\u884c\u3002

    break \u53ef\u4ee5\u7528\u4f86\u5f37\u5236\u8df3\u51fa\u8ff4\u5708\uff0c\u800c continue \u5247\u662f\u5f37\u5236\u8df3\u5230\u4e0b\u4e00\u6b21\u8ff4\u5708\u3002

    for i in range(1, 11):\n    if i == 5:\n        break\n    print(i, end=' ')\n
    ouput
    1 2 3 4\n

    \u53ef\u4ee5\u767c\u73fe\uff0ci == 5 \u7684\u6642\u5019\uff0c\u8ff4\u5708\u5c31\u88ab\u5f37\u5236\u4e2d\u65b7\u4e86\u3002

    for i in range(1, 11):\n    if i == 5:\n        continue\n    print(i, end=' ')\n
    ouput
    1 2 3 4 6 7 8 9 10\n

    \u53ef\u4ee5\u767c\u73fe\uff0c5 \u88ab\u8df3\u904e\u4e86\u3002

    "},{"location":"fundamental/python/repetition_structures/#nested_loop","title":"Nested Loop","text":"

    \u63a5\u8457\u4ecb\u7d39\u5de2\u72c0\u8ff4\u5708(Nested Loop)\uff0c\u4e5f\u5c31\u662f\u8ff4\u5708\u88e1\u9762\u9084\u6709\u8ff4\u5708\u3002\u505a\u500b\u6bd4\u55bb\u7684\u8a71\uff0c\u5982\u679c\u662f\u5169\u5c64\u7684\u8ff4\u5708\uff0c\u5c31\u50cf\u662f\u6642\u91dd\u8207\u5206\u91dd\uff0c\u5167\u5c64\u8ff4\u5708\u6bcf\u8dd1\u4e00\u5708\uff0c\u5916\u5c64\u8ff4\u5708\u624d\u8dd1\u4e00\u683c\u3002

    \u6211\u5011\u4f86\u5370\u4e00\u500b\u76f4\u89d2\u4e09\u89d2\u5f62\u5427\uff0c\u8f38\u5165\u4e00\u500b\u6578\u5b57 \\(n\\)\uff0c\u5370\u51fa \\(n\\) \u5c64\u7684\u76f4\u89d2\u4e09\u89d2\u5f62\uff0c\u5c07\u6700\u9802\u7aef\u7684\u90a3\u4e00\u5c64\u7de8\u865f\u70ba \\(0\\)\uff0c\u6700\u5e95\u7aef\u7684\u90a3\u4e00\u5c64\u7de8\u865f\u70ba \\(n-1\\)\uff0c\u5176\u4e2d\u7b2c \\(i\\) \u5c64\u6709 \\(i+1\\) \u500b\u661f\u661f *\u3002

    n = int(input())\n\nfor i in range(n):\n    for j in range(i + 1):\n        print('*', end='')\n    print()\n

    \u6211\u7a31\u5167\u5c64\u7684\u8ff4\u5708\u53eb\u505a j \u8ff4\u5708\uff0c\u5916\u5c64\u7684\u8ff4\u5708\u53eb\u505a i \u8ff4\u5708\u3002 j \u8ff4\u5708\u63a7\u5236\u6bcf\u4e00\u5c64\u7684\u661f\u661f\u6578\u91cf\uff0c\u800c i \u8ff4\u5708\u5247\u63a7\u5236\u7e3d\u5171\u6709\u5e7e\u5c64\u3002\u6bcf\u4e00\u5c64\u7684\u661f\u661f\u6578\u91cf\u90fd\u662f i + 1\uff0c\u6700\u5f8c\u6703\u63db\u884c\u3002

    input
    5\n
    output
    *\n**\n***\n****\n*****\n

    \u518d\u4f86\u770b\u4e00\u500b\u7d93\u5178\u7684\u4f8b\u5b50\uff0c\u4e5d\u4e5d\u4e58\u6cd5\u8868\u3002

    for i in range(1, 10):\n    for j in range(1, 10):\n        print(f\"{i} * {j} = {i * j}\", end='\\t')\n    print()\n
    output
    1 * 1 = 1   1 * 2 = 2   1 * 3 = 3   1 * 4 = 4   1 * 5 = 5   1 * 6 = 6   1 * 7 = 7   1 * 8 = 8   1 * 9 = 9   \n2 * 1 = 2   2 * 2 = 4   2 * 3 = 6   2 * 4 = 8   2 * 5 = 10  2 * 6 = 12  2 * 7 = 14  2 * 8 = 16  2 * 9 = 18  \n3 * 1 = 3   3 * 2 = 6   3 * 3 = 9   3 * 4 = 12  3 * 5 = 15  3 * 6 = 18  3 * 7 = 21  3 * 8 = 24  3 * 9 = 27  \n4 * 1 = 4   4 * 2 = 8   4 * 3 = 12  4 * 4 = 16  4 * 5 = 20  4 * 6 = 24  4 * 7 = 28  4 * 8 = 32  4 * 9 = 36  \n5 * 1 = 5   5 * 2 = 10  5 * 3 = 15  5 * 4 = 20  5 * 5 = 25  5 * 6 = 30  5 * 7 = 35  5 * 8 = 40  5 * 9 = 45  \n6 * 1 = 6   6 * 2 = 12  6 * 3 = 18  6 * 4 = 24  6 * 5 = 30  6 * 6 = 36  6 * 7 = 42  6 * 8 = 48  6 * 9 = 54  \n7 * 1 = 7   7 * 2 = 14  7 * 3 = 21  7 * 4 = 28  7 * 5 = 35  7 * 6 = 42  7 * 7 = 49  7 * 8 = 56  7 * 9 = 63  \n8 * 1 = 8   8 * 2 = 16  8 * 3 = 24  8 * 4 = 32  8 * 5 = 40  8 * 6 = 48  8 * 7 = 56  8 * 8 = 64  8 * 9 = 72  \n9 * 1 = 9   9 * 2 = 18  9 * 3 = 27  9 * 4 = 36  9 * 5 = 45  9 * 6 = 54  9 * 7 = 63  9 * 8 = 72  9 * 9 = 81  \n

    i \u63a7\u5236\u5217(Row)\uff0cj \u63a7\u5236\u884c(Column)\uff0c\u6bcf\u4e00\u5217\u7684\u6578\u5b57\u90fd\u662f i\uff0c\u6bcf\u4e00\u884c\u7684\u6578\u5b57\u90fd\u662f j\uff0c\u6240\u4ee5 i * j \u5c31\u662f\u76f8\u61c9\u7684\u4e58\u7a4d\u3002

    \u71b1\u8eab\u5b8c\u4e86\uff0c\u4f86\u770b\u4e00\u500b\u7a0d\u5fae\u8907\u96dc\u7684\u4f8b\u5b50\uff0c\u8f38\u5165\u4e00\u500b\u6578\u5b57\uff0c\u5224\u65b7\u4ed6\u662f\u4e0d\u662f\u8cea\u6578\u3002

    \u9019\u500b\u4f8b\u5b50\u6703\u662f\u7b49\u7b49\u66f4\u8907\u96dc\u7684\u4f8b\u5b50\u7684\u57fa\u790e\uff0c\u6240\u4ee5\u8acb\u4ed4\u7d30\u770b\u3002

    n = int(input())\nis_prime = True\n\nfor i in range(2, n):\n    if n % i == 0:\n        is_prime = False\n        break\n\nif is_prime:\n    print(\"Yes\")\nelse:\n    print(\"No\")\n
    input
    17\n4843\n
    ouput
    Yes\nNo\n

    n \u5982\u679c\u53ef\u4ee5\u6574\u9664 1 \u8207\u81ea\u5df1\u4ee5\u5916\u7684\u6578\u5b57\uff0c\u90a3\u5c31\u4e0d\u662f\u8cea\u6578\uff0c\u6211\u5011\u53ef\u4ee5\u7528 break \u4f86\u5f37\u5236\u8df3\u51fa\u8ff4\u5708\uff0c\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u8a08\u7b97\u3002

    \u6211\u5011\u628a\u554f\u984c\u7528\u5f97\u66f4\u8907\u96dc\uff0c\u8f38\u5165\u4e00\u500b\u6578\u5b57 \\(n\\)\uff0c\u8f38\u51fa\u5728 \\([1, n]\\) \u4e4b\u9593\u6700\u5927\u7684\u8cea\u6578\u3002

    \u5728\u9019\u88e1\u4ecb\u7d39\u5982\u4f55\u8b93 range \u5012\u8457\u6578\u56de\u4f86\u3002

    n = int(input())\n\nfor i in range(n, 0, -1):\n    is_prime = True\n    for j in range(2, i):\n        if i % j == 0:\n            is_prime = False\n            break\n\n    if is_prime:\n        print(f\"{i} is the largest prime in [1, {n}]\")\n        break\n
    input
    100\n2\n
    output
    97 is the largest prime in [1, 97]\n2 is the largest prime in [1, 2]\n

    i \u5217\u8209 \\([n, 1]\\) \u7684\u6578\u5b57\uff0c\u800c j \u5217\u8209 \\([2, i-1]\\) \u7684\u6578\u5b57\uff0c\u5982\u679c i \u53ef\u4ee5\u6574\u9664 j\uff0c\u90a3\u5c31\u4e0d\u662f\u8cea\u6578\uff0c\u99ac\u4e0a\u8df3\u51fa\u5167\u5c64 j \u8ff4\u5708\uff0c\u7e7c\u7e8c\u5217\u8209\u4e0b\u4e00\u500b\u6578\u5b57\u3002\u5982\u679c i \u662f\u8cea\u6578\uff0c\u90a3\u5c31\u5370\u51fa\u4f86\uff0c\u4e26\u4e14\u8df3\u51fa\u5916\u5c64 i \u8ff4\u5708\u3002

    \u8acb\u4f60\u4ed4\u7d30\u7aef\u8a73\u9019\u5169\u500b\u4f8b\u5b50\u4e2d\u5f37\u8abf\u7684\u884c\u6578\u3002

    @EditTime : 2024-01-30 16:33

    "},{"location":"fundamental/python/repetition_structures/#while_loop","title":"While loop","text":"

    \u63a5\u8457\u4f86\u4ecb\u7d39 while \u8ff4\u5708\uff0c\u4ed6\u7684\u4f7f\u7528\u5834\u666f\u662f\u7576\u4f60\u4e0d\u77e5\u9053\u8ff4\u5708\u8981\u57f7\u884c\u5e7e\u6b21\u7684\u6642\u5019\uff0c\u5c31\u53ef\u4ee5\u7528 while \u8ff4\u5708\uff0c\u4f46\u662f\u5225\u5beb\u51fa\u7121\u7aae\u8ff4\u5708(Infinite Loop)\u5594\u3002

    \u4f46\u5728\u5f80\u4e0b\u4e4b\u524d\uff0c\u5148\u4f86\u770b\u5982\u4f55\u7528 while \u8ff4\u5708\u4f86\u5370\u51fa \\(1\\) \u5230 \\(5\\)\u3002

    i = 1\nwhile i < 6:\n    print(i, end=\" \")\n    i += 1\n
    ouput
    1 2 3 4 5\n

    \u56de\u9867\u4e00\u4e0b for loop\uff0c\u4f60\u53ef\u4ee5\u767c\u73fe\u908f\u8f2f\u5176\u5be6\u4e00\u6a23\u3002

    \u7576\u689d\u4ef6\u6210\u7acb\u7684\u6642\u5019\uff0c\u5c31\u6703\u57f7\u884c\u8ff4\u5708\uff0c\u76f4\u5230\u689d\u4ef6\u4e0d\u6210\u7acb\u3002

    \u518d\u8209\u4e00\u500b\u4f8b\u5b50\uff0c\u8f38\u5165\u6b63\u6574\u6578 \\(n\\)\uff0c\u8f38\u51fa \\(n!\\)

    n = int(input())\ni = 1\nfact = 1\n\nwhile i <= n:\n    fact *= i\n    i += 1\n\nprint(fact)\n
    input
    5\n1\n
    ouput
    120\n1\n

    \u4f46\u76ee\u524d\u9019\u5169\u500b\u4f8b\u5b50\u7121\u6cd5\u770b\u51fa while \u7684\u9b45\u529b\uff0c\u56e0\u70ba\u4f60\u90fd\u77e5\u9053\u8ff4\u5708\u4ec0\u9ebc\u6642\u5019\u6703\u7d50\u675f\uff0c\u6240\u4ee5\u8ddf\u4f60\u4ecb\u7d39\u4e00\u500b\u7d93\u5178\u554f\u984c:

    \\[ \\text{The} \\ 3n+1 \\ \\text{Problem} \\ aka \\ \\text{Collatz Conjecture} \\]

    \u8003\u62c9\u8332\u731c\u60f3 wikipedia

    \u662f\u6307\u5c0d\u65bc\u6bcf\u4e00\u500b\u6b63\u6574\u6578\uff0c\u5982\u679c\u5b83\u662f\u5947\u6578\uff0c\u5247\u5c0d\u5b83\u4e583\u518d\u52a01\uff0c\u5982\u679c\u5b83\u662f\u5076\u6578\uff0c\u5247\u5c0d\u5b83\u9664\u4ee52\uff0c\u5982\u6b64\u5faa\u74b0\uff0c\u6700\u7d42\u90fd\u80fd\u5920\u5f97\u52301\u3002

    \u90a3\u6211\u5011\u8981\u5beb\u7684\u7a0b\u5f0f\u662f\uff0c\u8f38\u5165\u4e00\u500b\u6b63\u6574\u6578 \\(n\\)\uff0c\u8f38\u51fa\u4ed6\u6703\u5728\u5e7e\u6b65\u5f8c\u8b8a\u6210 \\(1\\)\u3002

    \\[ f(n)=\\begin{cases}\\frac{n}{2}, & \\text{if } n \\text{ is even} \\\\ 3n+1, & \\text{if } n \\text{ is odd}\\end{cases} \\]

    \u4f9d\u7167\u5b9a\u7fa9\uff0c\u6211\u5011\u53ef\u4ee5\u5beb\u51fa\u4ee5\u4e0b\u7a0b\u5f0f\u78bc:

    n = int(input())\nstep = 0\n\nwhile n != 1:\n    print(n, end=\" -> \")\n    if n % 2 == 0:\n        n = n // 2\n    else:\n        n = 3 * n + 1\n    step += 1\n\nprint(1)\nprint(f\"step = {step}\")\n
    input
    22\n1\n
    ouput
    22 -> 11 -> 34 -> 17 -> 52 -> 26 -> 13 -> 40 -> 20 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1\nstep = 15\n1\nstep = 0\n

    \u518d\u4f86\u4ecb\u7d39\u4e00\u500b\u7d93\u5178\u7684\u4f8b\u5b50\uff0c\u8f38\u5165\u4e00\u500b\u6b63\u6574\u6578 \\(n\\gt 1\\)\uff0c\u8f38\u51fa \\(n\\) \u7684\u8cea\u56e0\u6578\u5206\u89e3\u3002

    \u8acb\u4f60\u5148\u81ea\u5df1\u60f3\u4e00\u4e0b\uff0c\u518d\u770b\u770b\u53c3\u8003\u7a0b\u5f0f\u78bc\u3002

    Example
    n = int(input())\nfactor = 2\n\nwhile n != 1:\n    while n % factor == 0:\n        print(factor, end=' ')\n        n //= factor\n    factor += 1\n
    input
    20\n4843\n
    ouput
    2 2 5\n29 167\n

    \u5167\u5c64\u7684 while \u8ff4\u5708\u6703\u4e00\u76f4\u57f7\u884c\uff0c\u76f4\u5230 n \u4e0d\u662f factor \u7684\u500d\u6578\u70ba\u6b62\u3002\u5916\u5c64\u7684 while \u8ff4\u5708\u5247\u662f\u5217\u8209\u6240\u6709\u7684\u8cea\u56e0\u6578\uff0c\u76f4\u5230 n \u8b8a\u6210 \\(1\\) \u70ba\u6b62\u3002

    \u984c\u5916\u8a71\uff0c\u7576\u521d\u9047\u5230\u9019\u500b\u984c\u76ee\u7684\u6642\u5019\uff0c\u60f3\u4e86\u4e00\u4e0b\u7d50\u679c\u4e00\u6b21\u5c31AC\uff0c\u662f\u5f88\u6709\u6210\u5c31\u611f\u7684\u4e00\u4ef6\u4e8b\uff0c\u6240\u4ee5\u4e5f\u8acb\u4f60\u597d\u597d\u52aa\u529b\uff0c\u9010\u6b65\u57f9\u990a\u81ea\u4fe1\uff0c\u4f60\u4e5f\u53ef\u4ee5\u7684\u3002

    @EditTime : 2024-01-30 17:55

    "},{"location":"fundamental/python/repetition_structures/#bonus_for_else_and_while_else","title":"Bonus: for ... else and while ... else","text":"

    for \u8207 while \u8ff4\u5708\u90fd\u53ef\u4ee5\u642d\u914d else \u4f86\u4f7f\u7528\uff0c\u7576\u8ff4\u5708\u6b63\u5e38\u7d50\u675f\u7684\u6642\u5019(\u6c92\u6709 break )\uff0c\u5c31\u6703\u57f7\u884c else\u3002

    \n
    "},{"location":"fundamental/python/repetition_structures/#practice","title":"Practice","text":"

    Itsa - [C_MM03-\u6613] \u5169\u6578\u7e3d\u548c

    Reference code

    while True:\n    a, b = map(int, input().split())\n    print(a + b)\n
    \u9019\u984c\u6703\u51fa\u73fe\u5728\u9019\u88e1\uff0c\u55ae\u7d14\u662f\u56e0\u70ba\u8981\u91cd\u8907\u8f38\u5165\u3002

    Itsa - [C_MM26-\u6613] \u8f38\u51fa 1x1\u30012x2\u3001...\u3001NxN\u4e4b\u7d50\u679c

    Reference code
    N = int(input())\n\nfor i in range(1, N + 1):\n    print(f\"{i}*{i}={i * i}\")\n

    Itsa - [C_MM33-\u6613] \u627e1~N\u7684\u5b8c\u7f8e\u6578

    Reference code

    N = int(input())\n\nfor i in range(6, N + 1, 2):\n    s = 0\n    for j in range(1, i):\n        if i % j == 0:\n            s += j\n    if s == i:\n        if i == 6:\n            print(i, end='')\n        else:\n            print(' ' + str(i), end='')\nprint()\n
    \u9019\u662f\u66b4\u529b\u89e3\uff0c\u6703TLE\uff0c\u4e0b\u4e00\u7ae0\u6703\u4ecb\u7d39\u5982\u4f55\u6700\u4f73\u5316\uff0c \u4f46\u5982\u679c\u4f7f\u7528 C++ \u7684\u8a71\uff0c\u76f8\u540c\u908f\u8f2f\u7684\u7a0b\u5f0f\u78bc\u662f\u53ef\u4ee5AC\u7684\u3002

    Itsa - [C_MM34-\u6613] \u56e0\u6578\u554f\u984c

    Reference code
    N = int(input())\n\nprint(1, end=\"\")\nfor i in range(2, N + 1):\n    if N % i == 0:\n        print(f\" {i}\", end=\"\")\nprint()\n

    @EditTime : 2024-01-30 18:40

    "},{"location":"fundamental/python/repetition_structures/#assignment","title":"Assignment","text":"

    Itsa - [C_MM21-\u6613] \u7b97\u968e\u4e58

    Itsa - [C_MM25-\u6613] \u8a08\u7b97\u6b63\u6574\u6578\u88ab3\u6574\u9664\u4e4b\u6578\u503c\u4e4b\u7e3d\u548c

    Itsa - [C_MM27-\u6613] \u8a08\u7b97\u5169\u6574\u6578\u9593\u6240\u6709\u6574\u6578\u7684\u7e3d\u548c

    Itsa - [C_MM28-\u6613] \u8a08\u7b971\u5230N\u4e4b\u9593\u5c6c\u65bc5\u548c7\u7684\u500d\u6578

    Itsa - [C_MM29-\u6613] \u6700\u5927\u8cea\u6578\u554f\u984c

    Itsa - [C_MM30-\u6613] \u8cea\u6578\u5224\u5225

    Itsa - [C_MM31-\u6613] \u8a08\u7b971~N\u5167\u80fd\u88ab2\u8ddf3\u6574\u9664\uff0c\u4f46\u4e0d\u80fd\u88ab12\u6574\u9664\u7684\u6574\u6578\u7e3d\u548c

    Itsa - [C_MM40-\u6613] 1~N\u4e4b\u9593\u7684\u7e3d\u548c

    Itsa - [C_MM49-\u6613] \u9023\u7e8c1\u7684\u500d\u6578

    Itsa - [C_ST09-\u6613] \u661f\u865f\u77e9\u5f62\u8f38\u51fa

    Itsa - [C_ST11-\u6613] \u661f\u865f\u83f1\u5f62\u8f38\u51fa

    Itsa - [C_ST14-\u6613] \u6578\u5b57\u76f4\u89d2\u4e09\u89d2\u5f62\u8f38\u51fa

    @EditTime : 2024-01-30 21:51

    "},{"location":"fundamental/python/say_hello/","title":"Say Hello to Python!","text":""},{"location":"fundamental/python/say_hello/#first_program","title":"First Program","text":"

    \u55e8\uff0c\u9019\u662f\u4f60\u7b2c\u4e00\u500b Python \u7a0b\u5f0f\uff0c\u5728 Pycharm \u4e2d\u5efa\u7acb\u4e00\u500b main.py \u6a94\u6848\uff0c\u4e26\u5728\u6a94\u6848\u4e2d\u6253\u4e0a :

    # print(\"Hello Cat!\")\nprint(\"Hello World!\")\nprint('Hello Python!')\nprint(\"cheung4843\")\n

    \u6309\u4e0b\u57f7\u884c\u5f8c\uff0c\u4f60\u7684\u63a7\u5236\u53f0(Console)\u5c07\u6703\u5370\u51fa Hello World! \u63a5\u8457\u63db\u884c\uff0c\u518d\u5370\u51fa Hello Python!\uff0c\u63a5\u8457\u518d\u5370\u51fa\u6211 cheung4843\uff0c\u518d\u63db\u884c\u3002

    \u90a3 # print(\"Hello Cat!\") \u662f\u4ec0\u9ebc?\u4ee5\u4e95\u5b57\u865f\u70ba\u958b\u982d\u7684\uff0c\u88ab\u7a31\u70ba\u8a3b\u89e3\uff0c\u4ed6\u4e0d\u6703\u5728\u7a0b\u5f0f\u4e2d\u88ab\u57f7\u884c\uff0c\u4ed6\u53ef\u4ee5\u5e6b\u52a9\u4f60\u7406\u89e3\u7a0b\u5f0f\u78bc\uff0c\u6216\u8005\u8b93\u4f60\u7684\u7a0b\u5f0f\u78bc\u53ef\u8b80\u6027\u66f4\u4f73\u3002

    \u4e0d\u66c9\u5f97\u4f60\u662f\u5426\u6709\u767c\u73fe \"Hello World!\" \u8207 'Hello Python!' \u7684\u5dee\u7570?\u7576\u7136\u9664\u4e86\u5b57\u6bcd\u4e0d\u4e00\u6a23\u4e4b\u5916\uff0c\u9084\u6709\u96d9\u5f15\u865f\u8207\u55ae\u5f15\u865f\u7684\u5dee\u5225\uff0c\u4f46\u4ed6\u5011\u90fd\u88ab\u7a31\u70ba\u5b57\u4e32(String)\uff0c\u5728 Python \u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u6210\u5c0d\u7684\u96d9\u5f15\u865f\u8207\u55ae\u5f15\u865f\u4f86\u8868\u9054\u4e00\u500b\u5b57\u4e32\uff0c\u4f46\u662f\u4e0d\u80fd\u6df7\u7528\uff0c\u4f8b\u5982 :

    print(\"I love cats')\n

    \u57f7\u884c\u5f8c\uff0c\u4f60\u6703\u767c\u73fe\u63a7\u5236\u53f0\u8ddf\u4f60\u5831\u544a\u4e86\u932f\u8aa4\uff0c\u9019\u662f\u8a9e\u6cd5\u932f\u8aa4\uff0c\u800c\u5f8c\u7e8c\u5beb\u7a0b\u5f0f\u7684\u904e\u7a0b\u4e2d\uff0c\u4f60\u5c07\u906d\u9047\u8a31\u591a\u8a9e\u610f\u932f\u8aa4\u3002

    \u90a3\u4f60\u77e5\u9053\u4ec0\u9ebc\u662f\u7a7a\u5b57\u4e32\u55ce?

    print('')\nprint(\"\")\nprint(\"Above are nothing, right?\")\n

    \u57f7\u884c\u5b8c\u5f8c\uff0c\u4f60\u5c31\u77e5\u9053\u7a7a\u5b57\u4e32\u662f\u4ec0\u9ebc\u4e86\u5427?

    \u63a5\u8457\u6211\u5011\u4f86\u8b1b\u8b1b print \u9019\u500b\u6771\u897f\uff0c\u6211\u5011\u5728 Python \u4e2d\u7a31\u4ed6\u70ba\u51fd\u5f0f(Function)\uff0c\u6211\u5011\u8981\u5982\u4f55\u4f7f\u7528\u5462?\u4e5f\u5c31\u662f\u5728\u51fd\u5f0f\u7684\u540d\u7a31\u5f8c\u52a0\u4e0a\u4e00\u500b\u62ec\u865f()\u3002\u800c print \u662f Python \u5167\u5efa\u7d66\u6211\u5011\u7684\u300c\u5de5\u5177\u300d\uff0c\u5c31\u662f\u8aaa\uff0c\u6211\u5011\u4e0d\u77e5\u9053\u4ed6\u662f\u600e\u9ebc\u88ab\u9020\u51fa\u4f86\u7684\uff0c\u6211\u5011\u73fe\u968e\u6bb5\u53ea\u8981\u77e5\u9053\u600e\u9ebc\u7528\u5c31\u597d\uff0c\u6216\u8a31\u4f60\u53ef\u80fd\u807d\u904e\u4e00\u500b\u8001\u6389\u7259\u7684\u6bd4\u55bb\uff0c\u7a31\u51fd\u5f0f\u5c31\u50cf\u662f\u4e00\u500b\u9ed1\u76d2\u5b50\u3002

    \u95dc\u65bc\u51fd\u5f0f(Function)\uff0c\u6211\u6703\u5728\u5f80\u5f8c\u7684\u7ae0\u7bc0\u8ddf\u4f60\u4ecb\u7d39\uff0c\u800c\u73fe\u5728\u4f60\u53ea\u8981\u77e5\u9053 print() \u6703\u5c07\u62ec\u865f\u5167\u7684\u6771\u897f\u5370\u51fa\u4f86\uff0c\u4e26\u63db\u884c\u3002

    \u90a3\u5982\u679c\u6211\u4e0d\u60f3\u63db\u884c\u5462?

    print(\"You\")\nprint(\"are\")\nprint(\"my\", end=' ')\nprint(\"special\", end='\\n')\nprint(\"1234\", end=\"5\")\nprint(\"---------\")\n
    ouput
    You\nare\nmy special\n12345---------\n

    \u5728\u9019\u500b\u5947\u602a\u7684\u7a0b\u5f0f\u78bc\u4e2d\uff0c\u4f60\u767c\u73fe\u6211\u5728 print \u7684\u62ec\u865f\u4e2d\u591a\u52a0\u4e86\u4e00\u500b end= \u7684\u6771\u897f\uff0c\u8b93 print \u5370\u5b8c\u524d\u9762\u7684\u6771\u897f\u5f8c\uff0c\u518d\u5370\u51fa\u7b49\u65bc\u5f8c\u7684\u6771\u897f\u3002

    You are my special

    \u90a3 \\n \u662f\u4ec0\u9ebc\u6771\u897f?\u4ed6\u662f\u8df3\u812b\u5b57\u5143(Escape Character)\u5bb6\u65cf\u4e2d\u7684\u4e00\u54e1\uff0c\u4f60\u73fe\u5728\u53ea\u8981\u77e5\u9053\u4ed6\u80fd\u5920\u63db\u884c\u3002

    Note

    1. \u96d9\u5f15\u865f/\u55ae\u5f15\u865f\u570d\u4f4f\u7684\u5167\u5bb9\uff0c\u7a31\u70ba\u5b57\u4e32\uff0c\u4f8b\u5982 \"cheung4843\" \u8207 '114514 + 1919810' \uff0c\u4f46\u8a18\u4f4f\u55ae\u96d9\u5f15\u865f\u4e0d\u5f97\u6df7\u7528\u3002
    2. print(x, end=y) \u6703\u5370\u51fa x \uff0c\u518d\u5370\u51fa y\uff0c\u800c y \u9810\u8a2d\u70ba \\n \u4e5f\u5c31\u662f\u63db\u884c\u3002

    @EditTime : 2024-01-25 19:23

    Question

    1. \u90a3\u9ebc \"'\" \u8207 \"\"\" \u662f\u5408\u6cd5\u7684\u5b57\u4e32\u55ce?
    2. print() \u62ec\u865f\u5167\u6c92\u6709\u653e\u6771\u897f\u6703\u5370\u51fa\u4ec0\u9ebc?

    @EditTime : 2024-01-25 19:55

    "},{"location":"fundamental/python/selection_structures/","title":"Selection Structures","text":""},{"location":"fundamental/python/selection_structures/#introduction","title":"Introduction","text":"

    \u5728\u6211\u5011\u4eba\u751f\u4e2d\uff0c\u6211\u5011\u6703\u9762\u81e8\u5f88\u591a\u9078\u64c7\uff0c\u6703\u6839\u64da\u7576\u4e0b\u7684\u60c5\u6cc1\uff0c\u505a\u51fa\u4e0d\u540c\u7684\u6c7a\u5b9a\uff0c\u800c\u7a0b\u5f0f\u4e5f\u662f\u4e00\u6a23\uff0c\u6211\u5011\u53ef\u4ee5\u6839\u64da\u4e0d\u540c\u7684\u60c5\u6cc1\uff0c\u57f7\u884c\u4e0d\u540c\u7684\u7a0b\u5f0f\u78bc\uff0c\u9019\u7a31\u70ba\u9078\u64c7\u7d50\u69cb(Selection Structures)\uff0c\u662f\u6d41\u7a0b\u63a7\u5236\u7684\u4e00\u7a2e\u3002

    \u4f8b\u5982\uff0c\u6211\u6839\u64da\u5b78\u6e2c\u6210\u7e3e\uff0c\u4f86\u6c7a\u5b9a\u8981\u586b\u54ea\u4e9b\u5fd7\u9858\uff0c\u6216\u662f\u6211\u6839\u64da\u5929\u6c23\uff0c\u4f86\u6c7a\u5b9a\u8981\u4e0d\u8981\u5e36\u5098\u3002

    "},{"location":"fundamental/python/selection_structures/#if_elif_else","title":"if ... elif ... else","text":"

    \u5728\u5f80\u4e0b\u4e4b\u524d\uff0c\u8acb\u4f60\u5148\u56de\u60f3 Operators - Comparison Operators \u7684\u5167\u5bb9\uff0c\u6211\u5011\u53ef\u4ee5\u900f\u904e\u6bd4\u8f03\u904b\u7b97\u5b50\u4f86\u5f97\u5230\u4e00\u500b\u5e03\u6797\u503c\uff0c\u800c if \u6703\u6839\u64da True \u6216 False \u4f86\u6c7a\u5b9a\u662f\u5426\u57f7\u884c\u67d0\u6bb5\u7a0b\u5f0f\u78bc\u3002

    \u6211\u5011\u5148\u4f86\u770b\u4e00\u500b\u7c21\u55ae\u7684\u4f8b\u5b50:

    \u8f38\u5165\u4e00\u500b\u6574\u6578\uff0c\u8f38\u51fa\u4ed6\u7684\u7d55\u5c0d\u503c\u3002

    num = int(input(\"Enter a number: \"))\n\n# get the absolute value of the input\nif num < 0:\n    num = -num\n\nprint(num)\n
    input
    -1984\n1984\n
    ouput
    1984\n1984\n

    Ivan Torrent - \"1984\" Lyrics Video

    \u908f\u8f2f\u5f88\u7c21\u55ae\uff0c\u5982\u679c\u8f38\u5165\u7684\u6578\u5b57\u5c0f\u65bc\u96f6\uff0c\u90a3\u9ebc\u5c31\u5c07\u4ed6\u653e\u4e0a\u8ca0\u865f\u3002\u63d0\u9192\u4f60\u4e00\u4e0b\uff0c\u9019\u88e1\u7684 - \u8207 not \u4e00\u6a23\uff0c\u90fd\u662f\u4e00\u5143\u904b\u7b97\u5b50\uff0c

    \u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u6211\u5011\u53ea\u6709\u7528\u5230 if\uff0c\u63a5\u8457\u6211\u5011\u6709\u8acb else \u767b\u5834\u3002

    \u8acb\u770b\u4e0b\u4e00\u500b\u4f8b\u5b50\uff0c\u8f38\u5165\u4e00\u500b\u6574\u6578\uff0c\u5224\u65b7\u4ed6\u662f\u5947\u6578\u9084\u662f\u5076\u6578\u3002

    num = int(input(\"Enter a number: \"))\n\n# odd or even\nif num % 2 == 0:\n    print(\"Even\")\nelse:\n    print(\"Odd\")\n
    input
    1983\n-1982\n
    ouput
    Odd\nEven\n

    Timecop1983 - On the Run

    \u9019\u88e1\u6211\u5011\u7528\u5230\u4e86 else\uff0c\u7576 if \u7684\u689d\u4ef6\u4e0d\u6210\u7acb\u6642\uff0c\u5c31\u6703\u57f7\u884c else \u7684\u5167\u5bb9\u3002

    \u6211\u5011\u518d\u4f86\u770b\u66f4\u8907\u96dc\u7684\u4f8b\u5b50\uff0c\u8f38\u5165\u4f60\u7684\u5206\u6578\uff0c\u8f38\u51fa\u4f60\u7684\u8a55\u50f9\uff0c\u56e0\u70ba\u6709\u5f88\u591a\u7a2e\u8a55\u50f9\uff0c\u6240\u4ee5\u9700\u8981\u7528\u5230 elif\u3002

    \u7576 if \u7684\u689d\u4ef6\u4e0d\u6210\u7acb\u6642\uff0c\u5c31\u6703\u6aa2\u67e5\u4e0b\u9762 elif \u7684\u689d\u4ef6\uff0c\u5982\u679c elif \u7684\u689d\u4ef6\u6210\u7acb\uff0c\u5c31\u6703\u57f7\u884c elif \u7684\u5167\u5bb9\uff0c\u5982\u679c\u76ee\u524d\u7684 elif \u7684\u689d\u4ef6\u4e0d\u6210\u7acb\uff0c\u5c31\u6703\u6aa2\u67e5\u4e0b\u4e00\u500b elif \u7684\u689d\u4ef6\uff0c\u5982\u679c\u6240\u6709\u7684 elif \u7684\u689d\u4ef6\u90fd\u4e0d\u6210\u7acb\uff0c\u5c31\u6703\u57f7\u884c else \u7684\u5167\u5bb9\u3002

    \u9019\u6a23\u8b1b\u6216\u8a31\u6709\u9ede\u7e5e\u53e3\uff0c\u4f60\u53ef\u4ee5\u770b\u770b\u4e0b\u9762\u7684\u7a0b\u5f0f\u78bc\uff0c\u61c9\u8a72\u5c31\u80fd\u7406\u89e3\u4e86\u3002

    score = int(input(\"Enter your score: \"))\n\nif score >= 90:\n    print(\"A\")\n    print(\"Excellent!\")\nelif score >= 80:\n    print(\"B\")\nelif score >= 70:\n    print(\"C\")\nelif score >= 60:\n    print(\"D\")\nelse:\n    print(\"F\")\n
    input
    60\n90\n49\n
    ouput
    D\nA\nExcellent!\nF\n

    \u63a5\u4e0b\u4f86\u7d66\u4f60\u4e00\u500b\u53ef\u80fd\u6703\u7591\u60d1\u7684\u4f8b\u5b50:

    score = int(input(\"Enter your score: \"))\nif score >= 60:\n    print(\"D\")\nelif score >= 70:\n    print(\"C\")\nelif score >= 80:\n    print(\"B\")\nelif score >= 90:\n    print(\"A\")\n    print(\"Excellent!\")\nelse:\n    print(\"F\")\n
    input
    90\n
    ouput
    D\n

    \u4f60\u53ef\u80fd\u6703\u89ba\u5f97\u5947\u602a\uff0c\u70ba\u4ec0\u9ebc\u8f38\u5165 90 \u6703\u5370\u51fa D\uff0c\u800c\u4e0d\u662f A\uff0c\u9019\u662f\u56e0\u70ba if \u7684\u689d\u4ef6\u6210\u7acb\u6642\uff0c\u5c31\u6703\u57f7\u884c if \u7684\u5167\u5bb9\uff0c\u5c31\u4e0d\u6703\u6aa2\u67e5 elif \u7684\u689d\u4ef6\u4e86\u3002

    \u6240\u4ee5\uff0c\u4f60\u5728\u64b0\u5beb\u689d\u4ef6\u5f0f\u7684\u6642\u5019\uff0c\u8981\u6ce8\u610f\u9806\u5e8f\uff0c\u4ee5\u53ca\u78ba\u4fdd\u6bcf\u500b\u689d\u4ef6\u662f\u5426\u662f\u4e92\u65a5\u7684\u3002

    score = int(input(\"Enter your score: \"))\n\nif 70 > score >= 60:\n    print(\"D\")\nelif 80 > score >= 70:\n    print(\"C\")\nelif 90 > score >= 80:\n    print(\"B\")\nelif 100 >= score >= 90:\n    print(\"A\")\n    print(\"Excellent!\")\nelse:\n    print(\"F\")\n
    input
    90\n4843\n55\n
    ouput
    A\nExcellent!\nF\nF\n

    \u9019\u6a23\u5c31\u4e0d\u6703\u6709\u554f\u984c\u4e86\uff0c\u4f46\u662f\uff0c\u7576\u6211\u8f38\u5165\u8d85\u904e 100 \u7684\u5206\u6578\u6642\uff0c\u662f\u6703\u5370\u51fa F \u7684\uff0c\u4f60\u8a72\u600e\u9ebc\u89e3\u6c7a\u5462?

    "},{"location":"fundamental/python/selection_structures/#nested_if","title":"Nested if","text":"

    if \u7684\u5167\u5bb9\u53ef\u4ee5\u662f\u53e6\u4e00\u500b if\uff0c\u9019\u7a2e\u7d50\u69cb\u7a31\u70ba\u5de2\u72c0\u689d\u4ef6\u5f0f(Nested if)\u3002

    \u8209\u4e00\u500b\u4f8b\u5b50\uff0c\u5982\u679c\u4f60\u6709\u4e09\u500b\u6574\u6578 a, b, c \uff0c\u8acb\u4f60\u8f38\u51fa\u6700\u5927\u7684\u90a3\u500b\u6578\u5b57\u3002

    a, b, c = map(int, input().split())\nmax_one = None\n\nif a > b:\n    max_one = a\n    if c > max_one:\n        max_one = c\nelse:\n    max_one = b\n    if c > max_one:\n        max_one = c\n\nprint(max_one)\n
    input
    10 20 30\n12 12 12\n-3 -4 -5\n
    ouput
    30\n12\n-3\n

    \u60f3\u6cd5\u5f88\u7c21\u55ae\uff0c\u5148\u8b93 a, b \u9032\u884c\u6bd4\u8f03\uff0c\u5f97\u5230\u6700\u5927\u7684\u90a3\u500b\u6578\u5b57\uff0c\u518d\u8b93 c \u8207 max_one \u6bd4\u8f03\uff0c\u5f97\u5230\u6700\u5927\u7684\u90a3\u500b\u6578\u5b57\u3002

    \u9019\u88e1\u5077\u5077\u544a\u8a34\u4f60\u4e00\u500b\u795e\u5947\u5999\u5999\u5de5\u5177\uff0cmax()\uff0c\u4ed6\u6703\u627e\u51fa\u62ec\u865f\u5167\u7684\u6771\u897f\u4e2d\u6700\u5927\u7684\u90a3\u500b\u6578\u5b57\u3002

    a, b, c = map(int, input().split())\nprint(max(a, b, c))\n
    input
    114514 1919 810\n
    ouput
    114514\n
    "},{"location":"fundamental/python/selection_structures/#match_case","title":"match ... case","text":"

    \u5728 Python 3.10 \u4e2d\uff0c\u65b0\u589e\u4e86 match ... case \uff0c\u4f46\u907a\u61be\u7684\u662f\u4e00\u4e9b\u53e4\u8001\u7684 Online Judge \u7684 Python \u7248\u672c\u592a\u820a\u4e0d\u80fd\u7528\uff0c\u4f46\u6211\u9084\u662f\u60f3\u4ecb\u7d39\u7d66\u4f60\u3002

    \u6211\u5011\u5148\u4f86\u770b\u4e00\u500b\u5728 if ... elif ... else \u4e2d\u7684\u4f8b\u5b50:

    month = int(input(\"Enter a month (1-12): \"))\n\n# which season?\nif 3 <= month <= 5:\n    print(\"Spring\")\nelif 6 <= month <= 8:\n    print(\"Summer\")\nelif 9 <= month <= 11:\n    print(\"Fall\")\nelif month == 12 or month == 1 or month == 2:\n    print(\"Winter\")\nelse:\n    print(\"Invalid month\")\n
    input
    4\n7\n10\n1\n13\n
    ouput
    Spring\nSummer\nFall\nWinter\nInvalid month\n

    \u518d\u4f86\u770b\u770b match ... case \u7684\u7248\u672c:

    month = int(input(\"Enter a month (1-12): \"))\n\nmatch month:\n    case 3 | 4 | 5:\n        print(\"Spring\")\n    case 6 | 7 | 8:\n        print(\"Summer\")\n    case 9 | 10 | 11:\n        print(\"Autumn\")\n    case 12 | 1 | 2:\n        print(\"Winter\")\n    case _:\n        print(\"Invalid month\")\n
    input
    270\n11\n3\n
    ouput
    Invalid month\nAutumn\nSpring\n

    \u662f\u4e0d\u662f\u5f88\u7c21\u6f54\u5462?\u5982\u679c\u4f60\u6709\u5b78\u904e\u5176\u4ed6\u50cf\u662f C, C++, Java \u7b49\u8a9e\u8a00\uff0c\u4f60\u53ef\u80fd\u770b\u904e switch .. case\uff0c\u4f46\u662f match ... case \u66f4\u5f37\u5927!

    \u95dc\u65bc match ... case \u6211\u5c31\u4ecb\u7d39\u5230\u9019\u88e1\uff0c\u66f4\u91cd\u8981\u7684\u662f\uff0c\u4f60\u8981\u77e5\u9053 if ... elif ... else \u7684\u7528\u6cd5\u3002

    @EditTime : 2024-01-29 12:32

    "},{"location":"fundamental/python/selection_structures/#practice","title":"Practice","text":"

    Itsa - [C_MM09-\u6613] \u8a08\u7b97 i \u6b21\u65b9\u7684\u503c

    Reference code
    i = int(input())\nif i > 31:\n    print(\"Value of more than 31\")\nelse:\n    print(1 << i)\n

    Itsa - [C_MM13-\u6613] \u505c\u8eca\u8cbb\u8a08\u7b97

    Reference code
    h1, m1 = map(int, input().split())\nh2, m2 = map(int, input().split())\n\npaid = 0\nminutes = (h2 - h1) * 60 + (m2 - m1)\nif minutes > 240:\n    paid += ((minutes - 240) // 30) * 60\n    minutes = 240\nif minutes > 120:\n    paid += ((minutes - 120) // 30) * 40\n    minutes = 120\npaid += (minutes // 30) * 30\n\nprint(paid)\n

    Itsa - [C_MM15-\u6613] \u5224\u65b7\u5ea7\u6a19\u662f\u5426\u5728\u6b63\u65b9\u5f62\u7684\u7bc4\u570d\u5167

    Reference code
    x, y = map(int, input().split())\n\nif 0 <= x <= 100 and 0 <= y <= 100:\n    print(\"inside\")\nelse:\n    print(\"outside\")\n
    "},{"location":"fundamental/python/selection_structures/#assignment","title":"Assignment","text":"

    Itsa - [C_MM16-\u6613] \u5224\u65b7\u5ea7\u6a19\u662f\u5426\u5728\u5713\u5f62\u7684\u7bc4\u570d\u5167

    Itsa - [C_MM19-\u6613] \u96fb\u8a71\u8cbb\u8a08\u7b97

    Itsa - [C_MM24-\u6613] \u8a08\u7b97\u85aa\u6c34

    Itsa - [C_MM32-\u6613] Armstrong\u6578

    Itsa - [C_MM35-\u6613] \u5e73\u3001\u958f\u5e74\u5224\u5b9a

    Itsa - [C_MM36-\u6613] \u5b63\u7bc0\u5224\u5b9a

    Itsa - [C_MM37-\u6613] \u5224\u65b7\u5ea7\u6a19\u4f4d\u65bc\u4f55\u8655

    Itsa - [C_MM38-\u6613] \u5224\u65b73\u6574\u6578\u662f\u5426\u80fd\u69cb\u6210\u4e09\u89d2\u5f62\u4e4b\u4e09\u908a\u9577

    Itsa - [C_MM39-\u6613] \u5224\u65b7\u662f\u4f55\u7a2e\u4e09\u89d2\u5f62

    Itsa - [C_MM46-\u6613] \u8907\u6578\u904b\u7b97

    Itsa - [C_AR36-\u6613] \u661f\u5ea7\u67e5\u8a62

    @EditTime : 2024-01-29 14:38

    "},{"location":"fundamental/python/sets/","title":"Sets","text":""},{"location":"fundamental/python/sets/#introduction","title":"Introduction","text":"

    \u5982\u679c\u7d66\u4f60\u4e00\u500b\u4e32\u5217\uff0c\u8acb\u4f60\u6aa2\u67e5\u88e1\u9762\u6709\u6c92\u6709\u91cd\u8907\u7684\u5143\u7d20\uff0c\u4f60\u6703\u600e\u9ebc\u505a\u5462?\u4f60\u6703\u600e\u9ebc\u6a23\u78ba\u4fdd\u88e1\u9762\u7684\u5143\u7d20\u662f\u552f\u4e00\u7684\u5462?

    \u5728\u9019\u4e00\u7ae0\uff0c\u6211\u5011\u5c07\u6703\u5b78\u7fd2\u5230\u96c6\u5408(Set)\uff0c\u5b83\u6709\u4ee5\u4e0b\u7279\u6027:

    • \u7121\u5e8f: \u96c6\u5408\u88e1\u9762\u7684\u5143\u7d20\u662f\u6c92\u6709\u9806\u5e8f\u7684
    • \u4e0d\u91cd\u8907: \u96c6\u5408\u88e1\u9762\u7684\u5143\u7d20\u662f\u552f\u4e00\u7684
    • \u53ef\u8b8a: \u53ef\u4ee5\u65b0\u589e\u3001\u522a\u9664\u5143\u7d20\uff0c\u4f46\u662f\u88e1\u9762\u7684\u5143\u7d20\u5fc5\u9808\u662f\u4e0d\u53ef\u8b8a\u7684(immutable)
    • \u7528\u5927\u62ec\u865f{}\u4f86\u8868\u793a\uff0c\u88e1\u9762\u7684\u5143\u7d20\u7528\u9017\u865f,\u9694\u958b
    "},{"location":"fundamental/python/sets/#create_a_set","title":"Create a Set","text":"

    \u4f60\u53ef\u4ee5\u7528set()\u4f86\u5efa\u7acb\u4e00\u500b\u96c6\u5408\uff0c\u6216\u8005\u7528\u5927\u62ec\u865f{}\uff0c\u76f4\u63a5\u770b\u4f8b\u5b50:

    a = set(\"FOREVER\")\nprint(a)\n\nb = [4, 8, 4, 3]\nc = set(b)\nprint(c)\n\nd = {(0, 1), (1, 2), (2, 3)}\nprint(d)\nprint(type(d))\n\ne = {}\nprint(type(e))\n
    Output
    {'R', 'F', 'O', 'E', 'V'}\n{8, 3, 4}\n{(2, 3), (1, 2), (0, 1)}\n<class 'set'>\n<class 'dict'>\n

    SUHO(\uc218\ud638) _ FOREVER

    \u4f60\u5f97\u6ce8\u610f\uff0c\u5efa\u7acb\u7a7a\u96c6\u5408\u7684\u6642\u5019\uff0c\u4f60\u5fc5\u9808\u7528set()\uff0c\u56e0\u70ba{}\u662f\u7528\u4f86\u5efa\u7acb\u7a7a\u5b57\u5178\u7684\u3002

    \u4ee5\u53ca\u6240\u8b02\u7684\u7121\u5e8f\uff0c\u4f60\u8a66\u8457\u591a\u57f7\u884c\u5e7e\u6b21\u7a0b\u5f0f\uff0c\u4f60\u6703\u767c\u73fe\uff0c\u6bcf\u6b21\u8f38\u51fa\u7684\u7d50\u679c\u90fd\u4e0d\u4e00\u6a23\u3002

    \u4f60\u751a\u81f3\u53ef\u4ee5\u7528 Comprehension \u4f86\u5efa\u7acb\u96c6\u5408\u3002

    a = {1, 2, 3}\nb = {3, 4, 5}\ndiff_b = {x for x in b if x not in a}\nprint(diff_b)\n\nc = {x ** 2 for x in range(-3, 4)}\nprint(c)\n
    Output
    {4, 5}\n{0, 9, 4, 1}\n
    "},{"location":"fundamental/python/sets/#operations","title":"Operations","text":""},{"location":"fundamental/python/sets/#accessing_elements","title":"Accessing elements","text":"

    \u56e0\u70ba\u96c6\u5408\u662f\u7121\u5e8f\u7684\uff0c\u6240\u4ee5\u4f60\u4e0d\u80fd\u7528\u7d22\u5f15\u4f86\u5b58\u53d6\u5143\u7d20\uff0c\u4f46\u662f\u4f60\u53ef\u4ee5\u7528in\u4f86\u6aa2\u67e5\u5143\u7d20\u662f\u5426\u5b58\u5728\uff0c\u4ee5\u53ca\u642d\u914dfor\u8ff4\u5708\u4f86\u904d\u6b77\u96c6\u5408\u3002

    perfect_nums_set = {6, 28, 496, 8128, 33550336}\nprint(4843 in perfect_nums_set)\n\nfor num in perfect_nums_set:\n    print(num, end=' ')\n
    Output
    False\n33550336 8128 496 6 28 \n

    Question

    \u5c0d\u65bc\u4e00\u500b\u9577\u5ea6\u70ba \\(n\\) \u7684\u96c6\u5408\uff0c\u4f60\u8a8d\u70ba\u9700\u8981\u82b1\u5e7e\u500b\u6b65\u9a5f\u6aa2\u67e5\u67d0\u4e00\u500b\u5143\u7d20\u662f\u5426\u5b58\u5728?

    \u7b54\u6848\u53ef\u80fd\u6703\u8b93\u4f60\u9a5a\u8a1d\uff0c\u4e0d\u9700\u8981 \\(n\\) \u500b\u6b65\u9a5f\uff0c\u53ea\u8981\u5e7e\u500b\u6b65\u9a5f\u5c31\u597d\uff0c\u53ef\u4ee5\u8aaa\u662f\u99ac\u4e0a\u3002

    "},{"location":"fundamental/python/sets/#union","title":"Union","text":"

    \u4f60\u53ef\u4ee5\u7528| \u6216\u8005 union() \u4f86\u53d6\u5f97\u5169\u500b\u96c6\u5408\u7684\u806f\u96c6\u3002

    a = {1, 3, 5}\nb = {2, 4, 5, 6}\n\nprint(a.union(b))\nc = a | b\nprint(c)\n\na |= b\nprint(a)\n
    Output
    {1, 2, 3, 4, 5, 6}\n{1, 2, 3, 4, 5, 6}\n{1, 2, 3, 4, 5, 6}\n
    "},{"location":"fundamental/python/sets/#intersection","title":"Intersection","text":"

    \u4f60\u53ef\u4ee5\u7528& \u6216\u8005 intersection() \u4f86\u53d6\u5f97\u5169\u500b\u96c6\u5408\u7684\u4ea4\u96c6\u3002

    a = {1, 3, 5}\nb = {2, 4, 5, 6}\n\nprint(a.intersection(b))\nc = a & b\nprint(c)\n\na &= b\nprint(a)\n
    Output
    {5}\n{5}\n{5}\n
    "},{"location":"fundamental/python/sets/#difference","title":"Difference","text":"

    \u4f60\u53ef\u4ee5\u7528- \u6216\u8005 difference() \u4f86\u53d6\u5f97\u5169\u500b\u96c6\u5408\u7684\u5dee\u96c6\u3002

    a = {1, 3, 5}\nb = {2, 4, 5, 6}\n\nprint(a.difference(b))\nc = b - a\nprint(c)\n\na -= b\nprint(a)\n
    Output
    {1, 3}\n{2, 4, 6}\n{1, 3}\n

    \u6211\u5c31\u8209\u9019\u4e09\u500b\u4f8b\u5b50\uff0c\u5176\u4ed6\u8acb\u4f60\u81ea\u5df1\u67e5 Docs \u4f86\u5b78\u7fd2\u3002

    "},{"location":"fundamental/python/sets/#methods","title":"Methods","text":""},{"location":"fundamental/python/sets/#adding_elements","title":"Adding elements","text":"

    \u4f60\u53ef\u4ee5\u7528 add() \u4f86\u65b0\u589e\u5143\u7d20\u5230\u96c6\u5408\u4e2d\u3002

    nums_set = {1, 2, 3, 4, 5}\nnums_set.add(6)\nnums_set.add(3)\nprint(nums_set)\n
    Output
    {1, 2, 3, 4, 5, 6}\n

    \u4e5f\u53ef\u4ee5\u7528 update() \u4f86\u65b0\u589e\u591a\u500b\u5143\u7d20\u5230\u96c6\u5408\u4e2d\u3002

    \u5176\u5be6\u5c31\u8ddf |= \u4e00\u6a23\u3002

    nums_set = {1, 2, 3, 4, 5}\nnums_set.update({6, 7})\nprint(nums_set)\n\nnums_set.update([1, 8, 9], {10, 11})\nprint(nums_set)\n
    Output
    {1, 2, 3, 4, 5, 6, 7}\n{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}\n
    "},{"location":"fundamental/python/sets/#removing_elements","title":"Removing elements","text":"

    \u4f60\u53ef\u4ee5\u7528 remove() \u4f86\u79fb\u9664\u96c6\u5408\u4e2d\u7684\u5143\u7d20\uff0c\u5982\u679c\u5143\u7d20\u4e0d\u5b58\u5728\uff0c\u6703\u62cb\u51fa\u932f\u8aa4\u3002

    a = {1, 2, 3}\na.remove(1)\nprint(a)\na.remove(1)\nprint(a)\n
    Output
    {2, 3}\nKeyError: 1\n

    \u6216\u8005\u7528 discard() \u4f86\u79fb\u9664\u96c6\u5408\u4e2d\u7684\u5143\u7d20\uff0c\u5982\u679c\u5143\u7d20\u4e0d\u5b58\u5728\uff0c\u4e0d\u6703\u62cb\u51fa\u932f\u8aa4\u3002

    a = {1, 2, 3}\na.discard(2)\nprint(a)\na.discard(2)\nprint(a)\n
    Output
    {1, 3}\n{1, 3}\n

    \u90a3\u600e\u9ebc\u6e05\u7a7a\u5462?\u4f60\u53ef\u4ee5\u7528 clear() \u4f86\u6e05\u7a7a\u96c6\u5408\u3002

    a = {1, 2, 3}\na.clear()\nprint(len(a))\n
    Output
    0\n

    \u9084\u6709\u66f4\u591a\u7684\u65b9\u6cd5\uff0c\u8acb\u4f60\u81ea\u5df1\u67e5 Docs \u4f86\u5b78\u7fd2\uff0c\u4f46\u9019\u4e9b\u76ee\u524d\u61c9\u8a72\u5920\u4f60\u7528\u3002

    "},{"location":"fundamental/python/sets/#practice","title":"Practice","text":"

    Itsa - [C_AR20-\u6613] \u6aa2\u67e5\u6578\u503c\u662f\u5426\u6709\u91cd\u8907

    Reference code

    n = int(input())\nnum_set = set(input().split())\n\nif len(num_set) == n:\n    print(1)\nelse:\n    print(0)\n
    \u6aa2\u67e5\u6709\u6c92\u6709\u91cd\u8907\u7684\u5143\u7d20\uff0c\u9019\u500b\u554f\u984c\u5c31\u5f88\u9069\u5408\u7528\u96c6\u5408\u4f86\u89e3\u6c7a\uff0c\u56e0\u70ba\u96c6\u5408\u88e1\u9762\u7684\u5143\u7d20\u662f\u552f\u4e00\u7684\uff0c\u6240\u4ee5\u53ea\u8981\u6aa2\u67e5\u96c6\u5408\u7684\u9577\u5ea6\u662f\u5426\u7b49\u65bc\u8f38\u5165\u4e32\u5217\u7684\u9577\u5ea6\u5c31\u597d\u3002

    "},{"location":"fundamental/python/sets/#assignment","title":"Assignment","text":"

    \u5728 Itsa \u4e0a\u4e0d\u592a\u597d\u627e\u984c\u76ee\uff0c\u6240\u4ee5\u4e7e\u8106\u9644\u4e0a\u89e3\u7b54\u3002

    Itsa - [C_ST23-\u6613] \u76f8\u540c\u5b57\u96c6\u7684\u5b57\u4e32

    Reference code

    a, b = input().split(',')\na_set = set(str.lower(a))\na_set.discard(\" \")\nb_set = set(str.lower(b))\nb_set.discard(\" \")\n\nif a_set == b_set:\n    print(1)\nelse:\n    print(0)\n
    \u9019\u88e1\u61c9\u8a72\u80fd\u611f\u53d7 discard() \u7684\u7528\u8655\uff0c\u984c\u76ee\u8981\u6c42\u4e0d\u5340\u5206\u5927\u5c0f\u5beb\uff0c\u6240\u4ee5\u6211\u5011\u5148\u628a\u5b57\u4e32\u8f49\u6210\u5c0f\u5beb\uff0c\u7136\u5f8c\u518d\u628a\u7a7a\u767d\u5b57\u5143\u79fb\u9664(\u4e0d\u7ba1\u6709\u6c92\u6709)\uff0c\u6700\u5f8c\u518d\u6aa2\u67e5\u5169\u500b\u96c6\u5408\u662f\u5426\u76f8\u7b49\u3002

    @EditTime : 2024-02-06 23:16

    "},{"location":"fundamental/python/tuples/","title":"Tuples","text":""},{"location":"fundamental/python/tuples/#introduction","title":"Introduction","text":"

    \u6709\u4e86\u4e0a\u4e00\u7ae0\u7684\u57fa\u790e\u5f8c\uff0c\u6211\u76f8\u4fe1\u5e8f\u5c0d(Tuple)\u5c0d\u4f60\u4f86\u8aaa\u4e0d\u6703\u56f0\u96e3\uff0c\u56e0\u70ba\u5b83\u8ddf\u4e32\u5217(List)\u5f88\u50cf\uff0c\u53ea\u662f\u5b83\u662f\u7528\u5c0f\u62ec\u865f()\u4f86\u8868\u793a\uff0c\u800c\u4e14\u5b83\u662f\u4e0d\u53ef\u8b8a\u7684(immutable)\u3002\u9019\u8868\u793a\u4f60\u4e0d\u80fd\u65b0\u589e\u3001\u522a\u9664\u6216\u4fee\u6539\u88e1\u9762\u7684\u5143\u7d20\u3002\u90a3\u65e2\u7136\u5982\u6b64\uff0c\u70ba\u4ec0\u9ebc\u9084\u8981\u7528\u5b83\u5462?

    "},{"location":"fundamental/python/tuples/#create_a_tuple","title":"Create a Tuple","text":"

    \u8981\u5efa\u7acb\u4e00\u500b\u5e8f\u5c0d\u6709\u5f88\u591a\u7a2e\u65b9\u6cd5\uff0c\u6700\u7c21\u55ae\u7684\u5c31\u662f\u7528\u5c0f\u62ec\u865f()\u628a\u5143\u7d20\u5305\u8d77\u4f86\uff0c\u7528\u9017\u865f,\u9694\u958b\u5c31\u597d\u4e86\u3002

    \u4f46\u5728\u4e0b\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u4f60\u6703\u767c\u73fe\uff0c\u53ea\u6709\u4e00\u500b\u5143\u7d20\u6642\uff0c\u4f60\u5fc5\u9808\u5728\u5f8c\u9762\u52a0\u4e0a\u9017\u865f\u3002\u9019\u908a\u4f60\u81ea\u5df1\u8a66\u8a66\u770b\uff0c\u61c9\u8a72\u90fd\u80fd\u7406\u89e3\u3002

    empty = ()\none = (1,)\ntwo = (1, 2)\nprint(len(empty), len(one), len(two))\nprint(type(empty))\n\nodd = 1, 3, 5\nprint(odd)\nprint(type(odd))\n
    Output
    0 1 2\n<class 'tuple'>\n(1, 3, 5)\n(1, 3, 5)\n<class 'tuple'>\n

    \u4f60\u4e5f\u53ef\u4ee5\u7528tuple()\u4f86\u5efa\u7acb\u4e00\u500b\u5e8f\u5c0d\uff0c\u76f4\u63a5\u770b\u4f8b\u5b50:

    lst = [1, 2, 3, 4, 5]\ntup = tuple(lst)\nprint(tup)\n\ns = \"know me...\"\ns_tup = tuple(s)\nprint(s_tup)\n
    Output
    (1, 2, 3, 4, 5)\n('k', 'n', 'o', 'w', ' ', 'm', 'e', '.', '.', '.')\n

    \u516b\u6728\u6d77\u8389 \u300eknow me...\u300f

    \u9084\u8a18\u5f97 List Comprehension \u55ce?\u6211\u5011\u5c07\u4e2d\u62ec\u865f\u6539\u6210\u5c0f\u62ec\u865f\u8a66\u8a66\u770b:

    gen = (x ** 2 for x in range(5))\nprint(type(gen))\ntup = tuple(gen)\nprint(tup)\n
    Output
    <class 'generator'>\n(0, 1, 4, 9, 16)\n

    \u4f60\u6703\u767c\u73fe\uff0c\u7d50\u679c\u4e26\u975e\u662f\u4f60\u9810\u671f\u7684\u5e8f\u5c0d\uff0c\u800c\u662f\u7522\u751f\u5668(Generator)\uff0c\u4f60\u9084\u9700\u8981\u4f7f\u7528tuple()\u4f86\u8f49\u63db\u3002

    \u81f3\u65bc\u70ba\u4ec0\u9ebc\u8981\u7528\u7522\u751f\u5668(Generator)\uff0c\u6211\u6703\u5728\u672a\u4f86\u7684\u7ae0\u7bc0\u8ddf\u4f60\u8aaa\u660e\uff0c\u53c8\u6316\u5751\u4e86\u3002

    \u90a3\u9ebc\u52a0\u6cd5\u8ddf\u4e58\u6cd5\u5462?\u8ddf\u4e32\u5217(List)\u4e00\u6a23\uff0c\u4f60\u53ef\u4ee5\u7528\u52a0\u6cd5\u4f86\u5408\u4f75\u5169\u500b\u5e8f\u5c0d\uff0c\u7528\u4e58\u6cd5\u4f86\u8907\u88fd\u5e8f\u5c0d\u3002

    a = (1, 2, 3)\nb = 4, 5, 6\nc = a + b\nprint(c)\n\nd = a * 2 + b\nprint(d)\n
    Output
    (1, 2, 3, 4, 5, 6)\n(1, 2, 3, 1, 2, 3, 4, 5, 6)\n
    "},{"location":"fundamental/python/tuples/#operations","title":"Operations","text":""},{"location":"fundamental/python/tuples/#accessing_elements","title":"Accessing elements","text":"

    \u8ddf\u4e32\u5217(List)\u4e00\u6a23\uff0c\u4f60\u53ef\u4ee5\u7528\u7d22\u5f15\u4f86\u5b58\u53d6\u5e8f\u5c0d\u4e2d\u7684\u5143\u7d20\uff0c\u4e5f\u53ef\u4ee5\u7528\u8ca0\u7d22\u5f15\u4f86\u5f9e\u5f8c\u5b58\u53d6\u3002

    t = (1, 2, 3, 4, 5)\nprint(t[0], t[-1])\n
    Output
    1 5\n
    "},{"location":"fundamental/python/tuples/#slicing","title":"Slicing","text":"

    \u540c\u6a23\u7684\uff0c\u4f60\u4e5f\u53ef\u4ee5\u7528\u5207\u7247\u4f86\u53d6\u5f97\u5e8f\u5c0d\u4e2d\u7684\u5b50\u5e8f\u5c0d\u3002

    t = (1, 2, 3, 4, 5)\nprint(t[1:3])\nprint(t[:3])\nprint(t[3:])\nprint(t[:])\n
    Output
    (2, 3)\n(1, 2, 3)\n(4, 5)\n(1, 2, 3, 4, 5)\n
    "},{"location":"fundamental/python/tuples/#modifying_elements","title":"Modifying elements","text":"

    \u4f46\u662f\u4f60\u4e0d\u80fd\u4fee\u6539\u5e8f\u5c0d\u4e2d\u7684\u5143\u7d20\uff0c\u9019\u662f\u4e0d\u53ef\u8b8a\u7684(immutable)\uff0c\u662f\u6709\u6298\u8877\u7684\u65b9\u6cd5\u5566\uff0c\u5c31\u662f\u628a\u5e8f\u5c0d\u8f49\u63db\u6210\u4e32\u5217\uff0c\u518d\u8f49\u63db\u56de\u4f86\u3002

    cat_tup = (\"\ud83d\ude38\", \"\ud83d\ude3a\", \"\ud83d\ude3b\", [\"\ud83d\ude3f\", \"\ud83d\ude40\"])\n\ncat_lst = list(cat_tup)\ncat_lst[1] = \"\ud83d\ude3c\"\ncat_tup = tuple(cat_lst)\nprint(cat_tup)\n\ncat_tup[3][0] = \"\ud83d\ude3e\"\nprint(cat_tup)\n\ncat_tup[1] = \"\ud83d\ude3d\"\nprint(cat_tup)\n
    Output
    ('\ud83d\ude38', '\ud83d\ude3c', '\ud83d\ude3b', ['\ud83d\ude3f', '\ud83d\ude40'])\n('\ud83d\ude38', '\ud83d\ude3c', '\ud83d\ude3b', ['\ud83d\ude3e', '\ud83d\ude40'])\nTypeError: 'tuple' object does not support item assignment\n

    \u4f46\u4f60\u6709\u6c92\u6709\u89ba\u5f97\u602a\u602a\u7684\uff0c\u70ba\u4ec0\u9ebc\u6211\u53ef\u4ee5\u4fee\u6539\u5e8f\u5c0d\u4e2d\u7684\u4e32\u5217\u5462?

    "},{"location":"fundamental/python/tuples/#checking_elements","title":"Checking elements","text":"

    \u4f60\u53ef\u4ee5\u7528 in \u4f86\u6aa2\u67e5\u5143\u7d20\u662f\u5426\u5728\u5e8f\u5c0d\u4e2d\uff0c\u9019\u8ddf\u4e32\u5217\u662f\u4e00\u6a23\u7684\u3002

    fib = (0, 1, 1, 2, 3, 5, 8)\nprint(0 not in fib)\nprint(5 in fib)\n
    Output
    False\nTrue\n

    Question

    \u5c0d\u65bc\u9577\u5ea6\u70ba \\(n\\) \u7684\u7121\u5e8f\u5e8f\u5c0d\uff0c\u8981\u6aa2\u67e5\u67d0\u500b\u5143\u7d20\u662f\u5426\u5b58\u5728\u65bc\u5e8f\u5c0d\u4e2d\uff0c\u6700\u597d\u7684\u60c5\u6cc1\u4e0b\uff0c\u9700\u8981\u6aa2\u67e5\u591a\u5c11\u6b21?

    \u53c8\u662f\u719f\u6089\u7684\u554f\u984c\uff0c\u4f60\u53ef\u4ee5\u7684\u3002

    "},{"location":"fundamental/python/tuples/#methods","title":"Methods","text":"

    \u56e0\u70ba\u5e8f\u5c0d\u662f\u4e0d\u53ef\u8b8a\u7684(immutable)\uff0c\u6240\u4ee5\u53ea\u6709\u5169\u500b\u65b9\u6cd5\uff0c\u4e00\u500b\u662fcount()\uff0c\u4e00\u500b\u662findex()\uff0c\u4f60\u53ef\u4ee5\u81ea\u5df1\u8a66\u8a66\u770b\u3002

    "},{"location":"fundamental/python/tuples/#count","title":"count","text":"

    count() \u6703\u56de\u50b3\u62ec\u865f\u5167\u7684\u5143\u7d20\u5728\u5e8f\u5c0d\u4e2d\u51fa\u73fe\u7684\u6b21\u6578\uff0c\u7576\u7136 List \u4e5f\u6709\u9019\u500b\u65b9\u6cd5\uff0c\u4f46\u524d\u9762\u6211\u4e26\u6c92\u6709\u63d0\uff0c\u56e0\u70ba\u53ef\u4ee5\u653e\u5728\u9019\u88e1\u6c34\u5167\u5bb9(X

    t = ((1, 2), (3, 4), 6, 6, [7, 8])\nprint(t.count(1))\nprint(t.count([7, 8]))\nprint(t.count(6))\n
    Output
    0\n1\n2\n
    "},{"location":"fundamental/python/tuples/#index","title":"index","text":"

    index() \u6703\u56de\u50b3\u62ec\u865f\u5167\u7684\u5143\u7d20\u5728\u5e8f\u5c0d\u4e2d\u7684\u7d22\u5f15\uff0c\u4e00\u6a23\u7684\uff0cList \u4e5f\u6709\u9019\u500b\u65b9\u6cd5\u3002

    t = (\"Love Me Again\", \"John Newman\", 2013)\nprint(t.index(\"John Newman\"))\nprint(t.index(2014))\n
    Output
    1\nValueError: tuple.index(x): x not in tuple\n

    John Newman - Love Me Again

    "},{"location":"fundamental/python/tuples/#tuple_vs_list","title":"Tuple vs List","text":"
    • List
      • \u7528\u4e2d\u62ec\u865f[]\u8868\u793a
      • \u53ef\u8b8a\u7684(mutable)
      • \u4e0d\u53ef\u96dc\u6e4a(unhashable)
      • \u6548\u80fd\u8f03\u5dee
      • \u9069\u7528\u65bc\u983b\u7e41\u7684\u589e\u522a\u6539
    • Tuple
      • \u7528\u5c0f\u62ec\u865f()\u8868\u793a
      • \u4e0d\u53ef\u8b8a\u7684(immutable)
      • \u53ef\u96dc\u6e4a(hashable)
      • \u6548\u80fd\u8f03\u597d
      • \u9069\u7528\u65bc\u4e0d\u9700\u8981\u8b8a\u52d5\u7684\u8cc7\u6599\uff0c\u4f8b\u5982\u5e38\u6578\u3001\u5ea7\u6a19

    \u95dc\u65bc\u300c\u53ef\u96dc\u6e4a\u7684(hashable)\u300d\uff0c\u6211\u6703\u5728\u5b57\u5178(Dict)\u9019\u7ae0\u4e2d\u8ddf\u4f60\u8aaa\u660e\u3002

    "},{"location":"fundamental/python/tuples/#practice","title":"Practice","text":"

    Itsa - [C_AR04-\u6613] \u908a\u7de3\u5075\u6e2c

    Reference code

    N = int(input())\n\ndirs = ((0, 1), (0, -1), (1, 0), (-1, 0))\n\nfor k in range(N):\n    n, m = map(int, input().split())\n    pic = []\n    for _ in range(n):\n        pic.append(input().split())\n\n    for i in range(n):\n        for j in range(m):\n            if pic[i][j] == '0':\n                print('_ ', end='')\n            else:\n                is_edge = False\n                for d in dirs:\n                    x, y = i + d[0], j + d[1]\n                    if 0 <= x < n and 0 <= y < m and pic[x][y] == '0':\n                        is_edge = True\n                        break\n                if is_edge:\n                    print('0 ', end='')\n                else:\n                    print('_ ', end='')\n        print()\n\n    if k != N - 1:\n        print()\n
    \u65b9\u5411 dirs \u5c31\u5f88\u9069\u7528\u5e8f\u5c0d\u4f86\u8868\u793a\uff0c\u56e0\u70ba\u5b83\u662f\u56fa\u5b9a\u7684\uff0c\u4e0d\u6703\u8b8a\u52d5\u3002

    \u672a\u4f86\u5728\u5b78\u5716\u5f62\u8d70\u8a2a\u7684\u6642\u5019\uff0c\u4f60\u6703\u4e00\u76f4\u770b\u5230\u9019\u7a2e\u5beb\u6cd5\u3002

    \u5c0d\u4e86\uff0c \u8ff4\u5708\u8b8a\u6578 _ \u88ab\u7a31\u70ba\u6368\u68c4\u8b8a\u6578\uff0c\u8868\u793a\u4e0d\u9700\u8981\u7528\u5230\u9019\u500b\u8b8a\u6578\uff0c\u53ea\u662f\u70ba\u4e86\u914d\u5408\u8ff4\u5708\u8a9e\u6cd5\u800c\u5df2\u3002

    "},{"location":"fundamental/python/tuples/#assignment","title":"Assignment","text":"

    Itsa - [C_AR119-\u6613] \u5730\u96f7\u5371\u96aa\u6307\u6578\u8868

    Itsa - [C_AR139-\u6613] \u9ec3\u91d1\u63a2\u6e2c

    Itsa - [C-AR140-\u6613] \u6c42\u6700\u5927\u7ce7\u98df\u7522\u91cf

    @EditTime : 2024-02-04 21:15

    "},{"location":"fundamental/python/variable_and_input/","title":"Variable and Input","text":""},{"location":"fundamental/python/variable_and_input/#variable","title":"Variable","text":"

    \u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u4f86\u770b\u600e\u9ebc\u4f7f\u7528\u8b8a\u6578\uff0c\u4ee5\u53ca\u8f38\u5165\u81ea\u5df1\u60f3\u8981\u7684\u6771\u897f\u3002

    x = 4843\nprint(x)\n\nx = \"Memory Reboot\"\nprint(x)\n\nx = '4843'\nprint(x)\n

    \u6216\u8a31\u4f60\u53ef\u80fd\u6703\u89ba\u5f97\u795e\u5947\uff0c\u70ba\u4ec0\u9ebc x \u53ef\u4ee5\u8b8a\u6210\u6578\u5b57\uff0c\u53c8\u53ef\u4ee5\u8b8a\u6210\u5b57\u4e32\uff0c\u9084\u6709\u70ba\u4ec0\u9ebc\u7b2c\u4e00\u500b\u8207\u7b2c\u4e09\u500b\u7684\u8f38\u51fa\u6703\u662f\u76f8\u540c\u7684\u3002

    \u518d\u4f86\u7528\u4e00\u4e9b old-school \u7684\u6bd4\u55bb\uff0c\u4f60\u53ef\u4ee5\u5c07 x \u60f3\u50cf\u6210\u4e00\u500b\u7bb1\u5b50\uff0c\u800c\u7b49\u865f\u53f3\u908a\u7684\u300c\u503c\u300d\u5c31\u662f\u7bb1\u5b50\u88e1\u88dd\u7684\u6771\u897f\u3002\u65e2\u7136\u7bb1\u5b50\u88e1\u9762\u7684\u6771\u897f\u53ef\u4ee5\u8b8a\uff0c\u90a3\u6211\u662f\u4e0d\u662f\u53ef\u4ee5\u8aaa x \u662f\u4e00\u500b\u8b8a\u6578\u5462?

    \u4f46\u8acb\u4f60\u5148\u5fd8\u6389\u9019\u500b\u6bd4\u55bb\uff0c\u56e0\u70ba\u9019\u500b\u6bd4\u55bb\u4e26\u4e0d\u5b8c\u7f8e\uff0c\u4f46\u6211\u60f3\u4f60\u61c9\u8a72\u80fd\u5920\u7406\u89e3\uff0cx \u662f\u4e00\u500b\u8b8a\u6578\uff0c\u800c = \u662f\u6307\u6d3e\u904b\u7b97\u5b50(Assignment Operator)\uff0c\u4ed6\u6703\u5c07\u7b49\u865f\u53f3\u908a\u7684\u6771\u897f\u6307\u6d3e\u7d66\u7b49\u865f\u5de6\u908a\u7684\u8b8a\u6578\uff0c\u6216\u8005\u8aaa x \u6703\u6307\u5411\u7b49\u865f\u53f3\u908a\u7684\u7269\u4ef6(Object)\u3002

    Quote

    \u5728Python\u4e2d\uff0c\u4e00\u5207\u90fd\u662f\u7269\u4ef6\u3002

    \u8acb\u89c0\u770b\u4e0b\u9762\u7684\u52d5\u756b\u3002

    V\u00d8J, Narvent - Memory Reboot (4K Music Video)

    \u518d\u4f86\u4ecb\u7d39\u5e7e\u7a2e\u4e0d\u540c\u7684\u8b8a\u6578\u985e\u578b\u3002

    a = 114514\nprint(type(a))\nb = 1919810.0\nprint(type(b))\nc = 10e3\nprint(type(c))\nd = \"cheung4843\"\nprint(type(d))\ne = True\nprint(type(e))\nf = False\nprint(type(f))\nh = None\nprint(type(h))\n
    type \u544a\u8a34\u4f60\u62ec\u865f\u4e2d\u7684\u6771\u897f\u662f\u4ec0\u9ebc\u985e\u5225(Class)\u3002

    b \u8207 c \u90fd\u662f\u6d6e\u9ede\u6578(Float)\uff0c\u4e5f\u5c31\u662f\u5c0f\u6578\u9ede\u7684\u6578\u5b57\uff0c\u800c d \u5247\u662f\u5b57\u4e32\uff0ce \u8207 f \u5247\u662f\u5e03\u6797(Boolean)\uff0c\u800c h \u5247\u662f\u7a7a\u503c\u3002

    Note

    1. type(x) \u56de\u50b3 x \u7684\u985e\u5225\u3002
    2. int \u6574\u6578\u3002
    3. float \u6d6e\u9ede\u6578\u3002
    4. str \u5b57\u4e32\u3002
    5. bool \u5e03\u6797\u3002
    6. None \u7a7a\u503c\u3002

    Question

    1. print(type(3 + 4.0)) \u6703\u5370\u51fa\u4ec0\u9ebc?
    2. print(type(3 + True)) \u6703\u5370\u51fa\u4ec0\u9ebc?

    @EditTime : 2024-01-27 16:44

    "},{"location":"fundamental/python/variable_and_input/#input","title":"Input","text":"

    \u4f46\u662f\u5982\u679c\u6bcf\u6b21\u60f3\u8981\u4fee\u6539 x \u88e1\u9762\u7684\u6771\u897f\uff0c\u96e3\u9053\u90fd\u8981\u5728\u7a0b\u5f0f\u78bc\u4e2d\u4fee\u6539\u55ce?\u80fd\u4e0d\u80fd\u6211\u81ea\u5df1\u4f86\u8f38\u5165\u5462?

    x = input(\"Enter a number: \")\nprint(type(x))\ny = input(\"Enter another number: \")\nz = int(x) + int(y)\nprint(\"The sum is: \", z)\n

    \u5594\u5e79\uff0c\u600e\u9ebc\u4e00\u4e0b\u5b50\u591a\u51fa\u90a3\u9ebc\u591a\u6771\u897f\uff0c\u5225\u614c\uff0c\u6211\u4f86\u89e3\u91cb\uff0c\u4f46\u8acb\u4f60\u5148\u56de\u60f3\u5728\u524d\u4e00\u7bc0\u4e2d\u5b78\u904e\u7684\u6771\u897f\uff0c\u4f60\u53ef\u4ee5\u767c\u73fe input, int, \u90fd\u662f\u51fd\u5f0f\u3002\u800c input \u62ec\u865f\u4e2d\u7684\u5b57\u4e32\u6703\u986f\u793a\u5728\u63a7\u5236\u53f0\u4e2d\u63d0\u793a\u4f60\u8981\u8f38\u5165\u4ec0\u9ebc\uff0cint \u5247\u662f\u628a\u62ec\u865f\u4e2d\u7684\u6771\u897f\u7684\u985e\u5225\u8f49\u63db\u6210\u6574\u6578\u3002

    \u90a3\u70ba\u4ec0\u9ebc\u5370\u51fatype(x) \u5f97\u5230 <class 'str'> \u5462?\u4ee3\u8868 x \u662f\u4e00\u500b\u5b57\u4e32\uff0c\u9019\u662f\u56e0\u70ba input \u7e3d\u662f\u5c07\u4f60\u8f38\u5165\u9032\u4f86\u7684\u6771\u897f\u7576\u6210\u5b57\u4e32\uff0c\u4f46\u6211\u60f3\u8981\u8b93 z = x + y \u9019\u500b\u6578\u5b78\u5f0f\u5b50\u6210\u7acb\uff0c\u6240\u4ee5\u9700\u8981\u7528 int \u4f86\u5c07\u5b57\u4e32\u8f49\u63db\u6210\u6574\u6578\u518d\u9032\u884c\u904b\u7b97\u3002

    \u90a3\u4e0b\u9762\u9019\u500b\u7a0b\u5f0f\u78bc\u7684\u8f38\u51fa\u7d50\u679c\u662f\u4ec0\u9ebc\u5462?

    x = input(\"Enter a number: \")\nprint(type(x))\ny = input(\"Enter another number: \")\nz = x + y\nprint(\"The sum is: \", z)\n

    \u6c92\u932f\uff0c\u5b57\u4e32\u7684\u76f8\u52a0\uff0c\u5c31\u662f\u76f8\u9023\u3002\u90a3\u4f60\u8981\u4e0d\u8981\u8a66\u8a66\u770b\u76f8\u6e1b?

    \u63a5\u4e0b\u4f86\u6211\u5011\u4f86\u505a\u500b\u6709\u8da3\u7684\u5be6\u9a57\uff0c\u9806\u4fbf\u8a8d\u8b58\u4e00\u4e0b f-string

    a = 3.5\nb = int(a)\nprint(f'The value of b is {b}, and its type is {type(b)}')\nc = float(b)\nprint(f'The value of c is {c}, and its type is {type(c)}')\nprint(b == c)\n

    \u90a3 f-string \u662f\u4ec0\u9ebc\u6771\u897f\u5462?\u4ed6\u662f\u4e00\u7a2e\u5b57\u4e32\u683c\u5f0f\u5316(String Formatting)\u7684\u65b9\u6cd5\uff0c\u4ed6\u6703\u5c07\u62ec\u865f\u5167\u7684\u6771\u897f\u8f49\u63db\u6210\u5b57\u4e32\uff0c\u4e26\u5c07\u5b57\u4e32\u4e2d\u7684 {} \u66ff\u63db\u6210\u62ec\u865f\u5167\u7684\u6771\u897f\u3002

    \u800c\u57f7\u884c\u5b8c\u7a0b\u5f0f\u78bc\u5f8c\uff0c\u4f60\u6703\u767c\u73fe b \u8207 c \u7684\u985e\u5225\u4e0d\u540c\uff0c\u4f46\u4ed6\u5011\u7684\u503c\u537b\u76f8\u540c\uff0c\u9019\u662f\u56e0\u70ba int() \u8207 float() \u90fd\u662f\u5c07\u62ec\u865f\u5167\u7684\u6771\u897f\u8f49\u63db\u6210\u6574\u6578\u8207\u6d6e\u9ede\u6578\uff0c\u800c int() \u6703\u5c07\u6d6e\u9ede\u6578\u7684\u5c0f\u6578\u9ede\u6368\u53bb\uff0c\u800c float() \u5247\u6703\u5c07\u6574\u6578\u8f49\u63db\u6210\u6d6e\u9ede\u6578\u3002

    \u90a3\u9ebc b == c \u662f\u4ec0\u9ebc\u610f\u601d\u5462?\u5176\u4e2d == \u662f\u6bd4\u8f03\u904b\u7b97\u5b50(Comparison Operator)\uff0c\u4ed6\u6703\u6bd4\u8f03\u7b49\u865f\u5de6\u53f3\u5169\u908a\u7684\u6771\u897f\u662f\u5426\u76f8\u7b49\uff0c\u5982\u679c\u76f8\u7b49\uff0c\u5247\u56de\u50b3 True\uff0c\u5426\u5247\u56de\u50b3 False\u3002

    "},{"location":"fundamental/python/variable_and_input/#multiple_input","title":"Multiple Input","text":"

    \u90a3\u5982\u679c\u6211\u4eca\u5929\u60f3\u8981\u4e00\u6b21\u8f38\u5165\u597d\u5e7e\u500b\u5b57\u4e32\uff0c\u6bcf\u4e00\u500b\u5b57\u4e32\u4ee5\u7a7a\u683c\u4f86\u9694\u958b\u5462? \u4f46\u5728\u9019\u4e4b\u524d\uff0c\u6211\u5011\u5148\u4f86\u770b\u4e00\u500b\u5c0f\u7a0b\u5f0f :

    a, b = \"Hello World\".split()\nprint(a)\nprint(b)\n

    \u6211\u77e5\u9053\u602a\u602a\u7684\uff0c\u70ba\u4ec0\u9ebc\u5b57\u4e32\u5f8c\u9762\u63a5\u4e86\u4e00\u500b .split() \u5462?\u5728\u9019\u88e1\u4ed6\u5f88\u50cf\u662f\u51fd\u5f0f\uff0c\u4f46\u53c8\u4e0d\u662f\u51fd\u5f0f\uff0c\u90a3\u4ed6\u53eb\u4ec0\u9ebc\u5462?\u4ed6\u88ab\u7a31\u70ba \"Hello World\" \u9019\u500b\u5b57\u4e32\u7684\u65b9\u6cd5(Method)\uff0c\u4f46\u672a\u4f86\u4f60\u53ef\u80fd\u9084\u6703\u807d\u5230\u985e\u5225\u65b9\u6cd5(Class Method)\uff0c\u4ee5\u53ca\u975c\u614b\u65b9\u6cd5(Static Method) \u7b49\u540d\u8a5e\uff0c\u6211\u6015\u4f60\u6703\u641e\u6df7\uff0c\u6240\u4ee5\u4f60\u5c31\u5148\u8a8d\u9017\u9ede\u5f8c\u9762\u7684\u662f\u300c\u65b9\u6cd5\u300d\u5c31\u597d\u4e86\u3002

    \u800c .split() \u6703\u628a\u5b57\u4e32\u4ee5\u62ec\u865f\u5167\u7684\u6771\u897f\u4f86\u5207\u5272\u5b57\u4e32\u4e26\u56de\u50b3(\u90a3\u4f60\u60f3\u60f3\u62ec\u865f\u5167\u4ec0\u9ebc\u90fd\u6c92\u653e\uff0c\u9810\u8a2d\u6703\u662f\u4ec0\u9ebc?)\uff0c\u800c\u770b\u770b\u7b49\u865f\u5de6\u908a\uff0c\u6211\u7528 a, b \u53bb\u63a5\u8457\uff0c\u9019\u7a31\u70ba\u958b\u7bb1(Unpacking)

    \u90a3\u73fe\u5728\u4f60\u61c9\u8a72\u80fd\u770b\u61c2\u4e0b\u9762\u7684\u7a0b\u5f0f\u78bc\u4e86\uff0c\u56e0\u70ba input() \u4e5f\u6703\u56de\u50b3\u4e00\u500b\u5b57\u4e32\uff0c\u56e0\u6b64\u4ed6\u4e5f\u80fd\u5920\u4f7f\u7528 .split()

    a, b = input().split()\nprint(a)\nprint(b)\n

    Note

    1. input() \u63a5\u53d7\u8f38\u5165\uff0c\u56de\u50b3\u4e00\u500b\u5b57\u4e32\u3002
    2. int(x) \u5c07 x \u8f49\u63db\u6210\u6574\u6578\u3002
    3. float(x) \u5c07 x \u8f49\u63db\u6210\u6d6e\u9ede\u6578\u3002
    4. str.split() \u4ee5\u62ec\u865f\u5167\u7684\u6771\u897f\u4f86\u5207\u5272\u5b57\u4e32\uff0c\u4e26\u56de\u50b3\u3002

    @EditTime : 2024-01-25 22:13

    Question

    1. print(int(input()) + int(input())) \u6703\u5370\u51fa\u4ec0\u9ebc?
    2. 124.spilt(\"1\") \u662f\u5408\u6cd5\u7684\u55ce?
    3. bool(0) \u8207 bool(1) \u6703\u56de\u50b3\u4ec0\u9ebc?
    4. \u770b\u4ee5\u4e0b\u7684\u7a0b\u5f0f\u78bc\uff0c\u70ba\u4ec0\u9ebc\u5b83\u5011\u7684\u529f\u80fd\u76f8\u540c\uff0ca \u8207 b \u6210\u529f\u4e92\u63db\u4e86\u5462?
    a, b = 4, 5\nprint(a, b)\na, b = b, a\nprint(a, b)\n
    a, b = 4, 5\nprint(a, b)\ntmp = a\na = b\nb = tmp\nprint(a, b)\n

    @EditTime : 2024-01-25 22:17

    "},{"location":"fundamental/python/variable_and_input/#practice","title":"Practice","text":"

    \u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u4f60\u5b78\u5230\u4e86:

    Info

    1. \u5982\u4f55\u4f7f\u7528 print() \u8207 input()\u3002
    2. \u77e5\u9053\u8b8a\u6578\u7684\u6982\u5ff5\u3002
    3. \u77e5\u9053 type(x) \u8207 int(x), float(x) \u7684\u7528\u9014\u3002
    4. \u77e5\u9053 str.split() \u7684\u7528\u9014\u3002
    5. \u77e5\u9053\u5982\u4f55\u4f7f\u7528 f-string\u3002

    \u90a3\u73fe\u5728\u4f60\u53ef\u4ee5\u8a66\u8a66\u770b\u4ee5\u4e0b\u7684\u984c\u76ee\u4e86\u3002

    ZeroJudge - a001. \u54c8\u56c9

    Reference code
    word = input()\nprint(f'hello, {word}')\n

    @EditTime : 2024-01-27 17:02

    "},{"location":"blog/archive/2024/","title":"2024","text":""},{"location":"blog/category/blog/","title":"Blog","text":""}]} \ No newline at end of file diff --git a/sitemap.xml b/sitemap.xml index e995b01..b752a7f 100755 --- a/sitemap.xml +++ b/sitemap.xml @@ -2,82 +2,102 @@ https://cheung4843.github.io/LMcpsBook/ - 2024-02-04 + 2024-02-06 daily https://cheung4843.github.io/LMcpsBook/about/ - 2024-02-04 + 2024-02-06 daily https://cheung4843.github.io/LMcpsBook/license/ - 2024-02-04 + 2024-02-06 + daily + + + https://cheung4843.github.io/LMcpsBook/blog/ + 2024-02-06 + daily + + + https://cheung4843.github.io/LMcpsBook/blog/2024/02/06/hello-blog-/ + 2024-02-06 daily https://cheung4843.github.io/LMcpsBook/fundamental/ - 2024-02-04 + 2024-02-06 daily https://cheung4843.github.io/LMcpsBook/fundamental/cpp/ - 2024-02-04 + 2024-02-06 daily https://cheung4843.github.io/LMcpsBook/fundamental/cpp/create_env/ - 2024-02-04 + 2024-02-06 daily https://cheung4843.github.io/LMcpsBook/fundamental/cpp/hello_world/ - 2024-02-04 + 2024-02-06 daily https://cheung4843.github.io/LMcpsBook/fundamental/python/ - 2024-02-04 + 2024-02-06 daily https://cheung4843.github.io/LMcpsBook/fundamental/python/lists/ - 2024-02-04 + 2024-02-06 daily https://cheung4843.github.io/LMcpsBook/fundamental/python/operators/ - 2024-02-04 + 2024-02-06 daily https://cheung4843.github.io/LMcpsBook/fundamental/python/repetition_structures/ - 2024-02-04 + 2024-02-06 daily https://cheung4843.github.io/LMcpsBook/fundamental/python/say_hello/ - 2024-02-04 + 2024-02-06 daily https://cheung4843.github.io/LMcpsBook/fundamental/python/selection_structures/ - 2024-02-04 + 2024-02-06 daily https://cheung4843.github.io/LMcpsBook/fundamental/python/sets/ - 2024-02-04 + 2024-02-06 daily https://cheung4843.github.io/LMcpsBook/fundamental/python/tuples/ - 2024-02-04 + 2024-02-06 daily https://cheung4843.github.io/LMcpsBook/fundamental/python/variable_and_input/ - 2024-02-04 + 2024-02-06 + daily + + + https://cheung4843.github.io/LMcpsBook/blog/archive/2024/ + 2024-02-06 + daily + + + https://cheung4843.github.io/LMcpsBook/blog/category/blog/ + 2024-02-06 daily \ No newline at end of file diff --git a/sitemap.xml.gz b/sitemap.xml.gz index 203fdccb148b454a9676414fbfc08df3e708d335..68c5d66a97968c0ef9db903cfdcef5cb28f18d82 100755 GIT binary patch literal 386 zcmV-|0e$`-iwFoTPQqmZ|8r?{Wo=<_E_iKh0Ns{7Z-X!phWGpm#15u3iqeV@sY9oB zYiDH41*{sMYadYleGQ4K?3Jpxx7a?tK0W?8=`D_5y^2P#PNF`EBx+QH3p)(YD&AQu*vO;GG+rVe$8$VxhLA%dd;%L#3e@D>b^ zB=3GIM|Kc2SP1eUj?dNFv_Zmy0`VUn0m5uy8jK3_#z$@?uN72WHT04u(_M{Y$Y gM>xC4Ac%#xGA-Kqk1YB+_I|8r?{Wo=<_E_iKh0Ns{NPs1<_hVT0oRqt!c=wYC?lQ?jK z8=R{w_1cIu4zaVce^2%yv^x@7@FlVJ+IkYpO6twmWU@VY(rBCft|;>itioQ~p~>Ih zo|o%<(=O`Z4FP9SY^ljdX7?z>JkJGbhDkaq&<}#t7#$LqpeT!nyj^6`js?!Ulhp=Q zd#pmSOiT)PsMgheF=!scw$LbEUX`OK#1B!6qxd>k5>ME-t8!H>%hj^1qT~|0lBrSJ z0d^if+g@sOsKr&}3?+W3e!(ZV82IKXjaFa@Zk}@&Y%eFUEKO3Z%DLotl?Tbtf!!yE zK7ujW&FD>^6uUd{h&DxJqlqa+aCG1$qfZjvg9FwaALowP2gSidk_RDq=uShMBs>^U q|Dg$x<_L3eCe0h)ORweDKqqbAY3u&tr+8XotJ`m>8|MJs3jhG}^Qde9