From ad47910c08592160299ffbf1d24cd490c78758f1 Mon Sep 17 00:00:00 2001 From: Cheung4843 <46809977+cheung4843@users.noreply.github.com> Date: Sun, 28 Jan 2024 22:19:05 +0800 Subject: [PATCH] Deployed 3d1c40f with MkDocs version: 1.5.3 --- fundamental/python/operators/index.html | 414 ++++++++++++------------ search/search_index.json | 2 +- sitemap.xml.gz | Bin 277 -> 277 bytes 3 files changed, 212 insertions(+), 204 deletions(-) diff --git a/fundamental/python/operators/index.html b/fundamental/python/operators/index.html index 22177db..b71813f 100755 --- a/fundamental/python/operators/index.html +++ b/fundamental/python/operators/index.html @@ -957,6 +957,14 @@

Arithmetic OperatorsThe sum of 1 to 100 is 5050

這邊要提醒你的是,運算子之間有優先順序,當你不確定結果的時候,請善用括號。

+
1
+2
x = 'A' + 'n' + 'i' + 'm' + 'a' + 'l' + 's'
+print(x)
+
+
ouput
Animals
+
+

Martin Garrix - Animals (Official Video)

+

再請你留意一件事,不同類別對於運算子的作用是不同的,例如字串的 + 會將兩個字串相連,而整數的 + 則會將兩個整數相加。

Question

    @@ -968,55 +976,55 @@

    Arithmetic OperatorsComparison Operators

    比較運算子的結果會是 TrueFalse,這個結果我們稱為布林值。

    我們來以直角三角形的性質來做一些比較運算子的練習。

    -
    1
    -2
    -3
    -4
    -5
    -6
    -7
    -8
    -9
    a, b, c = 3, 4, 5
    -
    -print(a < b)
    -print(a > b)
    -print(a <= b)
    -print(a >= b)
    -print(a ** 2 + b ** 2 == c ** 2)
    -print(a ** 2 + b ** 2 != c ** 2)
    -print((a + b) > c)
    -
    -
    ouput
    1
    -2
    -3
    -4
    -5
    -6
    False
    -True
    -False
    -True
    -False
    -True
    -
    -

    這邊要提醒你, == 是比較運算子,而 = 是指派運算子,他們的意思是不一樣的。

    -

    最後來看一個例子:

    1
     2
     3
     4
     5
    -6
    age = 14
    -print(12 <= age <= 18)
    -
    -x, y, z = 1, 2, 3
    -print(x < y < z)
    -print(x < y and y < z)
    -

    +6 +7 +8 +9
a, b, c = 3, 4, 5
+
+print(a < b)
+print(a > b)
+print(a <= b)
+print(a >= b)
+print(a ** 2 + b ** 2 == c ** 2)
+print(a ** 2 + b ** 2 != c ** 2)
+print((a + b) > c)
+
ouput
1
 2
-3
True
+3
+4
+5
+6
False
 True
-True
+False
+True
+False
+True
+
+

這邊要提醒你, == 是比較運算子,而 = 是指派運算子,他們的意思是不一樣的。

+

最後來看一個例子: +

1
+2
+3
+4
+5
+6
age = 14
+print(12 <= age <= 18)
+
+x, y, z = 1, 2, 3
+print(x < y < z)
+print(x < y and y < z)
+

+
ouput
1
+2
+3
True
+True
+True
 

在Python中,我們可以將比較運算子連接起來,這樣的寫法可以讓我們的程式碼更簡潔。

@@ -1028,29 +1036,29 @@

Comparison OperatorsLogical Operators

我們繼續往下看,這邊我們要介紹邏輯運算子,他可以將多個布林值結合成一個布林值。

-
1
-2
-3
-4
-5
-6
-7
-8
has_license = True
-is_drunk = False
-age = 18
-
-print(f"Can I drive a car? {has_license and not is_drunk and age >= 18}")
-print(not has_license)
-print(not is_drunk)
-print(age >= 18 or is_drunk or not has_license)
+
1
+2
+3
+4
+5
+6
+7
+8
has_license = True
+is_drunk = False
+age = 18
+
+print(f"Can I drive a car? {has_license and not is_drunk and age >= 18}")
+print(not has_license)
+print(not is_drunk)
+print(age >= 18 or is_drunk or not has_license)
 
-
ouput
1
-2
-3
-4
Can I drive a car? True
-False
-True
-True
+
ouput
1
+2
+3
+4
Can I drive a car? True
+False
+True
+True
 

這邊要提醒你的是, and 只有在所有布林值都是 True 的時候,結果才會是 True,而 or 只要有一個布林值是 True,結果就會是 True

因此有所謂的短路求值(Short-circuit Evaluation),當 and 的第一個布林值是 False,後面的布林值就不會被計算,因為結果一定是 False;而 or 的第一個布林值是 True,後面的布林值就不會被評估,因為結果一定是 True

@@ -1066,123 +1074,123 @@

Logical OperatorsBitwise Operators

在這邊我們要介紹位元運算子,他是對二進位的運算,我們可以用 bin() 來觀察二進位的結果。

-
 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
-10
-11
a, b = 2, 3
-print(f"a={bin(a)}")
-print(f"b={bin(b)}")
-
-print(a & b, bin(a & b))
-print(a | b, bin(a | b))
-print(a ^ b, bin(a ^ b))
-print(~a, bin(~a))
-
-print(a << 1, bin(a << 1))
-print(a >> 1, bin(a >> 1))
+
 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+10
+11
a, b = 2, 3
+print(f"a={bin(a)}")
+print(f"b={bin(b)}")
+
+print(a & b, bin(a & b))
+print(a | b, bin(a | b))
+print(a ^ b, bin(a ^ b))
+print(~a, bin(~a))
+
+print(a << 1, bin(a << 1))
+print(a >> 1, bin(a >> 1))
 
-
ouput
1
-2
-3
-4
-5
-6
-7
-8
a=0b10
-b=0b11
-2 0b10
-3 0b11
-1 0b1
--3 -0b11
-4 0b100
-1 0b1
+
ouput
1
+2
+3
+4
+5
+6
+7
+8
a=0b10
+b=0b11
+2 0b10
+3 0b11
+1 0b1
+-3 -0b11
+4 0b100
+1 0b1
 
-

& 是位元的 and| 是位元的 or^ 是位元的 xor~ 是位元的 not<< 是位元的左移, >> 是位元的右移。

+

& 是位元的 and| 是位元的 or^ 是位元間的進行互斥或運算, ~ 是位元的 not<< 是位元的左移, >> 是位元的右移。

在往下之前,請你先想想我們該如何判斷一個數字是奇數還是偶數,我們可以用 % 來判斷,但是我們也可以用位元運算來判斷。

-
1
-2
-3
a, b = 5678, 4843
-print(f"Is a even? {a % 2 == 0}")
-print(f"Is b odd? {b & 1 == 1}")
+
1
+2
+3
a, b = 5678, 4843
+print(f"Is a even? {a % 2 == 0}")
+print(f"Is b odd? {b & 1 == 1}")
 
-
ouput
1
-2
Is a even? True
-Is b odd? True
+
ouput
1
+2
Is a even? True
+Is b odd? True
 

Question

  1. 如何判斷一個數字是 2 的冪?
  2. -
  3. 如何讓一個數字變成自己的 16 倍,但不能用 * 乘法運算子?
  4. +
  5. 如何得到一個數字的 16 倍,但不能用 * 乘法運算子?

Assignment Operators

我們已經學會了一些運算子,現在我們要來學習一些指派運算子,他可以將運算結果指定給變數。

先來看看一個簡單的例子,我們可以用 += 來將變數加上某個值,這個運算子可以讓我們的程式碼更簡潔。

-
1
-2
-3
-4
-5
x = 1
-x = x + 2
-y = 1
-y += 2
-print(x, y)
+
1
+2
+3
+4
+5
x = 1
+x = x + 2
+y = 1
+y += 2
+print(x, y)
 
-
ouput
3 3
+
ouput
3 3
 

再來看看其他的指派運算子。

-
 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
-10
-11
-12
-13
x = 1
-x += 2
-print(x)
-x -= 1
-print(x)
-x *= 3
-print(x)
-x //= 2
-print(x)
-x **= 2
-print(x)
-x <<= 1
-print(x)
+
 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+10
+11
+12
+13
x = 1
+x += 2
+print(x)
+x -= 1
+print(x)
+x *= 3
+print(x)
+x //= 2
+print(x)
+x **= 2
+print(x)
+x <<= 1
+print(x)
 
-
ouput
1
-2
-3
-4
-5
-6
3
-2
-6
-3
-9
-18
+
ouput
1
+2
+3
+4
+5
+6
3
+2
+6
+3
+9
+18
 

對了,請你別忘記 = 也是一個指派運算子。

-
1
-2
x = y = z = 1
-print(x, y, z)
+
1
+2
x = y = z = 1
+print(x, y, z)
 
-
ouput
1 1 1
+
ouput
1 1 1
 

希望這個例子可以讓你更熟悉指派運算子。

@@ -1196,36 +1204,36 @@

Bonus: f-string for float為了能讓你練習一些題目,我先在這裡介紹如何印出浮點數到指定位數。

Say Hello to Python - Input 中,有稍微提過,如果你完全沒印象,請你回去複習一下。

給你浮點數 x ,請你印出 x 的平方根與平方,並且只印出小數點後兩位。

-
1
-2
-3
x = 3.1415926
-print(f"The square root of {x} is {x ** 0.5:.2f}")
-print(f"The square of {x} is {x ** 2:.2f}")
+
1
+2
+3
x = 3.1415926
+print(f"The square root of {x} is {x ** 0.5:.2f}")
+print(f"The square of {x} is {x ** 2:.2f}")
 
-
ouput
1
-2
The square root of 3.1415926 is 1.77
-The square of 3.1415926 is 9.87
+
ouput
1
+2
The square root of 3.1415926 is 1.77
+The square of 3.1415926 is 9.87
 

@EditTime : 2024-01-27 11:52

Bonus: map for input

再次複習 Say Hello to Python - Mutiple Input 中的例子,我們可以用 split() 來將輸入的字串切割成多個字串。

但是如果我們想要將這些字串轉換成整數,我們可以怎麼做呢?

-
1
-2
a, b, c = input().split()
-print(int(a) + int(b) + int(c))
+
1
+2
a, b, c = input().split()
+print(int(a) + int(b) + int(c))
 
-
input
1 2 3
+
input
1 2 3
 
-
ouput
6
+
ouput
6
 

雖然這樣寫也可以,但是如果我們想要輸入很多個數字,這樣寫就會很麻煩,這時候我們可以用 map() 來幫助我們。

-
1
-2
a, b, c = map(int, input().split())
-print(a + b + c)
+
1
+2
a, b, c = map(int, input().split())
+print(a + b + c)
 
-
input
4 5 6
+
input
4 5 6
 
-
ouput
15
+
ouput
15
 

map(function, iterable) 會將 iterable 中的每一個元素都丟進 function 中,在這裡的 iterableinput().split(),而 functionint,因此 map(int, input().split()) 會將 input().split() 中的每一個元素都轉換成整數。

你可以嘗試將使用別的函式,例如 floatstr,但請你記得不要加上括號,因為我們只是要將函式的名稱傳進去,而不是要執行函式。

@@ -1239,11 +1247,11 @@

Practice Reference code -
1
-2
-3
a, b, h = map(int, input().split())
-area = (a + b) * h / 2
-print(f"Trapezoid area:{area}")
+
1
+2
+3
a, b, h = map(int, input().split())
+area = (a + b) * h / 2
+print(f"Trapezoid area:{area}")
 
@@ -1252,11 +1260,11 @@

Practice Reference code -
1
-2
-3
a, b = map(int, input().split())
-area = a * b / 2
-print(area)
+
1
+2
+3
a, b = map(int, input().split())
+area = a * b / 2
+print(area)
 
@@ -1265,17 +1273,17 @@

Practice Reference code -
1
-2
-3
-4
-5
-6
a, b = map(int, input().split())
-
-print(f"{a}+{b}={a + b}")
-print(f"{a}*{b}={a * b}")
-print(f"{a}-{b}={a - b}")
-print(f"{a}/{b}={a // b}...{a % b}")
+
1
+2
+3
+4
+5
+6
a, b = map(int, input().split())
+
+print(f"{a}+{b}={a + b}")
+print(f"{a}*{b}={a * b}")
+print(f"{a}-{b}={a - b}")
+print(f"{a}/{b}={a // b}...{a % b}")
 
@@ -1284,11 +1292,11 @@

Practice Reference code -
1
-2
-3
mile = int(input())
-km = mile * 1.6
-print(f"{km:.1f}")
+
1
+2
+3
mile = int(input())
+km = mile * 1.6
+print(f"{km:.1f}")
 

Assignment

diff --git a/search/search_index.json b/search/search_index.json index 81a3896..f0827b0 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":"

Success

  1. \u7b2c\u4e8c\u4efb\u793e\u9577
"},{"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":""},{"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/operators/","title":"Operators","text":""},{"location":"fundamental/python/operators/#arithmetic_operators","title":"Arithmetic Operators","text":"

\u6211\u5011\u5df2\u7d93\u6703\u600e\u9ebc\u4f7f\u7528\u8b8a\u6578\u3001\u81ea\u5df1\u8f38\u5165\u503c\u3001\u4ee5\u53ca\u5370\u51fa\u503c\uff0c\u73fe\u5728\u6211\u5011\u8981\u4f86\u5b78\u7fd2\u4e00\u4e9b\u904b\u7b97\u5b50\uff0c\u8b93\u6211\u5011\u53ef\u4ee5\u5c0d\u8b8a\u6578\u505a\u4e00\u4e9b\u904b\u7b97\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

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\u7684 xor\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\u8b93\u4e00\u500b\u6578\u5b57\u8b8a\u6210\u81ea\u5df1\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 Say Hello to Python - 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\u9019\u4e9b\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!

Success

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

Success

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

Success

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

Success

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":"

Success

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

Success

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

Success

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

Success

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

Success

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

Success

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

@EditTime : 2024-01-28 22:03

"},{"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\u800c\u4ed6\u7684\u4f5c\u7528\uff0c\u4f60\u4ee5\u5f8c\u4e00\u5b9a\u80fd\u9ad4\u6703\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/say_hello/#variable_and_input","title":"Variable and Input","text":""},{"location":"fundamental/python/say_hello/#variable","title":"Variable","text":"

\u63a5\u4e0b\u4f86\uff0c\u4f86\u9ede\u597d\u73a9\u7684\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/say_hello/#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/say_hello/#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/say_hello/#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":"

Success

  1. \u7b2c\u4e8c\u4efb\u793e\u9577
"},{"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":""},{"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/operators/","title":"Operators","text":""},{"location":"fundamental/python/operators/#arithmetic_operators","title":"Arithmetic Operators","text":"

\u6211\u5011\u5df2\u7d93\u6703\u600e\u9ebc\u4f7f\u7528\u8b8a\u6578\u3001\u81ea\u5df1\u8f38\u5165\u503c\u3001\u4ee5\u53ca\u5370\u51fa\u503c\uff0c\u73fe\u5728\u6211\u5011\u8981\u4f86\u5b78\u7fd2\u4e00\u4e9b\u904b\u7b97\u5b50\uff0c\u8b93\u6211\u5011\u53ef\u4ee5\u5c0d\u8b8a\u6578\u505a\u4e00\u4e9b\u904b\u7b97\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 Say Hello to Python - 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\u9019\u4e9b\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!

Success

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

Success

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

Success

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

Success

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":"

Success

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

Success

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

Success

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

Success

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

Success

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

Success

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

@EditTime : 2024-01-28 22:03

"},{"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\u800c\u4ed6\u7684\u4f5c\u7528\uff0c\u4f60\u4ee5\u5f8c\u4e00\u5b9a\u80fd\u9ad4\u6703\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/say_hello/#variable_and_input","title":"Variable and Input","text":""},{"location":"fundamental/python/say_hello/#variable","title":"Variable","text":"

\u63a5\u4e0b\u4f86\uff0c\u4f86\u9ede\u597d\u73a9\u7684\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/say_hello/#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/say_hello/#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/say_hello/#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 diff --git a/sitemap.xml.gz b/sitemap.xml.gz index 98b57288fd5447a2b08f970dfcd3ac46cadf326e..60e9dd62dbc83e5d1e30867a4c5d56e7fc6aac51 100755 GIT binary patch delta 15 WcmbQrG?j@>zMF$1GHD|lKO+DhR|9bX delta 15 WcmbQrG?j@>zMF%iE`B2$KO+DiCIgcI