diff --git a/README.md b/README.md index c3ceb72..add033d 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,7 @@ For the colors in the notes, here are their meanings: * OrangeRed: to highlight important parts. * DarkOrange: to indicate definitions. * Fuchsia: to indicate different points in a list. +* MediumSeaGreen: to indicate subpoints under one point in a list. * LawnGreen: to indicate mathematical proof. * IndianRed: to indicate examples. diff --git a/README_zh_CN.md b/README_zh_CN.md index 50ccc49..112c9ba 100644 --- a/README_zh_CN.md +++ b/README_zh_CN.md @@ -122,6 +122,7 @@ For English version please check [here](README.md) * OrangeRed: 强调重点内容。 * DarkOrange: 表示定义。 * Fuchsia: 表示列表中不同内容。 +* MediumSeaGreen: 代表列表中一点的分支。 * LawnGreen: 代表数学证明。 * IndianRed: 代表示例。 diff --git a/Writerside/topics/Python-Programming.topic b/Writerside/topics/Python-Programming.topic index 10240c5..74031ce 100644 --- a/Writerside/topics/Python-Programming.topic +++ b/Writerside/topics/Python-Programming.topic @@ -15,33 +15,19 @@

In Python, all objects produce two string representations:

  • -

    The - str - is legible to humans. -

    +

    The str is legible to humans.

  • -

    The - repr - is legible to Python - interpreter. -

    +

    The repr is legible to Python interpreter.

  • -

    - repr: - Provides a string - representation that can be used to recreate the object. It's - designed for debugging and introspection. It aims for a more - precise and detailed description, often including the object's - type. -

    -

    - Examples: -

    - +

    repr: Provides a string representation that can be used to + recreate the object. It's designed for debugging and introspection. It aims for a more + precise and detailed description, often including the object's type.

    +

    Examples:

    + class MyClass: def __init__(self, value): self.value = value @@ -53,16 +39,10 @@
  • -

    - repr: - Provides a human- - readable string representation of the object. It's designed to be - easily understood by humans. -

    -

    - Examples: -

    - +

    str: Provides a human-readable string representation of the object. It's + designed to be easily understood by humans.

    +

    Examples:

    + class MyClass: def __init__(self, value): self.value = value @@ -79,10 +59,8 @@

    For more information on strings, please visit strings in Java.

    -

    - Examples in Python: -

    - +

    Examples in Python:

    + name = "Nate" age = 19 @@ -92,7 +70,7 @@ print(f"2 + 2 = {(lambda x: x + x)(2)}") # 2 + 2 = 4 - + s = "I have a dream!" print(s[2:6]) # "have" print(s[2:]) # "have a dream!" @@ -100,7 +78,7 @@ print(s[-1:-3]) # "" No result! print(s[::-1]) # "!maerd a evah I", -1 refers to the step - + s = "dream" s1 = s.captialize() # "Dream" s2 = "i have a dream!" @@ -108,7 +86,7 @@ s4 = "I HAVE A DREAM!" s5 = s4.lower() # "i have a dream!" - + s = " I have a dream! " s1 = s.strip() # "I have a dream!" strip() can remove whitespace, \n, \t s2 = "I have a dream!" @@ -129,16 +107,14 @@ -

    - Examples: -

    - +

    Examples

    + lst = ["I", "have", "a", "dream!"] s = " ".join(lst) # "I have a dream!" for item in lst: - print(item) # I have a dream! + print(item) # I have a dream! - + lst = [] lst.append("I") # ["I"] lst.insert(0, "have") # ["have", "I"] @@ -149,7 +125,7 @@ lst.remove("I") # ["a"] lst.[0] = "me" # ["me"] - + lst = [1, 2, 4, 3, 5] lst.sort() # [1, 2, 3, 4, 5] lst.sort(reverse=True) # [5, 4, 3, 2, 1] @@ -160,10 +136,8 @@
    -

    - Examples: -

    - +

    Examples

    + t = () t = (1, 2, 3) t[1] = 4 # TypeError -> Tuple is unchangeable! @@ -180,33 +154,11 @@
    - - s = {} - print(type(s)) # <class 'dict'> - s = {1, 2, 3} - s = set() - -

    Set cannot contain unhashable type aka mutable type.

    - -
  • -

    - Hashable type: - int, float, - string, tuple, bool. -

    -
  • -
  • -

    - Unhashable type: - list, set, - dict. -

    -
  • -
    - +

    Examples

    + s = {1, 2, 3, []} # TypeError: unhashable type: 'list' - + s = set() s.add(1) s.add(2) @@ -215,7 +167,7 @@ s.pop() s.remove(2) - + s1 = {1, 2, 3} s2 = {3, 4, 5} print(s1 & s2) # {3} @@ -227,24 +179,39 @@ print(s1 - s2) # {1, 2} print(s1.difference(s2)) # {1, 2} - - - -

    Some important notes:

    - + +
  • -

    A key of a dictionary cannot be a list or a dictionary (or any - mutable type).

    +

    Set is unordered and unchangeable.

  • -

    Two keys cannnot be equal.

    + + s = {} + print(type(s)) # <class 'dict'> + s = {1, 2, 3} + s = set() + +
  • +
  • +

    Set cannot contain unhashable type aka mutable type.

    + +
  • +

    Hashable type: int, float, string, tuple, bool.

    +
  • +
  • +

    Unhashable type: list, set, dict.

    +
  • +
    -
    - + +
    + +

    Examples

    + dic = {1: "I", 2: "have", 3: "a", 4: "dream!"} - + dic = {} # dic = dict() dic[1] = "I" dic[2] = "have" # {1: "I", 2: "have"} @@ -254,14 +221,14 @@ otherwise, add and set the key-value pair to default in dictionary. ''' - + dict = {1: "I", 2: "have", 3: "a", 4: "dream!"} dict.pop(4) # {1: "I", 2: "have", 3: "a"} print(dict[0]) # KeyError print(dict.get(0)) # None - + dict = {1: "I", 2: "have", 3: "a", 4: "dream!"} for key in dict: print(key, dict[key]) @@ -275,122 +242,86 @@ for key, value in dict.items(): print(key, value) - + dict = {1: "I", 2: "have", 3: "a", 4: "dream!"} for key in dict: dict.pop(key) # RuntimeError: dictionary changed size during iteration - + dict = {1: "I", 2: "have", 3: "a", 4: "dream!"} for key in list(dict.keys()): dict.pop(key) # No error + +

    Some important notes:

    + +
  • +

    A key of a dictionary cannot be a list or a dictionary (or any mutable type).

    +
  • +
  • +

    Two keys cannnot be equal.

    +
  • +
    +
  • -

    - ASCII: - 1 bytes, 8 bits. -

    +

    ASCII: 1 bytes, 8 bits.

  • -

    - ANSI: - A standard. 2 bytes, 16 - bits. -

    +

    ANSI: A standard. 2 bytes, 16 bits.

  • -

    - Mainland China: - GB2312 => GBK (Windows). -

    +

    Mainland China: GB2312 => GBK (Windows).

  • -

    - Taiwan, China: - Big5. -

    +

    Taiwan, China: Big5.

  • -

    - Japan: - JIS. -

    +

    Japan: JIS.

  • -

    - Unicode: -

    +

    Unicode:

  • -

    - UCS-2: - 2 bytes, 16 bits. -

    +

    UCS-2: 2 bytes, 16 bits.

  • -

    - UCS-4: - 4 bytes, 32 bits - . -

    +

    UCS-4: 4 bytes, 32 bits.

  • -

    - UTF: - All the same as Unicode, - except that the length is changeable. -

    +

    UTF: All the same as Unicode, except that the length is + changeable.

  • -

    - English: - 1 byte, 8 bits - . -

    +

    English: 1 byte, 8 bits .

  • -

    - Some of European languages: - - 2 bytes, 16 bits. -

    +

    Some of European languages: 2 bytes, 16 bits.

  • -

    - Chinese: - 3 bytes, 24 - bits. -

    +

    Chinese: 3 bytes, 24 bits.

  • -

    - UTF-16: - Shortest length is 16 - bits. -

    +

    UTF-16: Shortest length is 16 bits.

  • Priority:

    -

    () => not => and => or

    +

    () => not => and => or

    -

    - Higher-order function: - A function that takes a function as an argument value or returns - a function as a return value. -

    +

    Higher-order function: A function that takes a function as an argument + value or returns a function as a return value.