diff --git a/Writerside/topics/C-Programming.md b/Writerside/topics/C-Programming.md index 4be5e90..b734fb2 100644 --- a/Writerside/topics/C-Programming.md +++ b/Writerside/topics/C-Programming.md @@ -1249,7 +1249,7 @@ element from the range) and returns:

-## Ⅲ Object-Oriented Programming +## Ⅲ Object-Oriented Programming {id="object"} ### 9 Classes and Consts @@ -1736,7 +1736,7 @@ val = static_cast(size); // val: lvalue, static_cast(size): rvalue #### 12.2 Move Semantics -### 13 Inheritance +### 13 Inheritance {id="inheritance"} #### 13.1 Namespace diff --git a/Writerside/topics/Python-Programming.md b/Writerside/topics/Python-Programming.md index b37f7ce..39155b2 100644 --- a/Writerside/topics/Python-Programming.md +++ b/Writerside/topics/Python-Programming.md @@ -6,8 +6,58 @@ ### 1.1 Strings +#### 1.1.1 String Representation + +

In Python, all objects produce two string representations:

+ + +
  • The str is legible to humans. +
  • +
  • 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:

    + +class MyClass: + def __init__(self, value): + self.value = value + def __repr__(self): + return f"MyClass({self.value})" +obj = MyClass(10) +print(repr(obj)) # Output: MyClass(10) + +
  • + +
  • +

    repr: 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 + def __str__(self): + return f"MyClass with value: {self.value}" +obj = MyClass(10) +print(str(obj)) # Output: MyClass with value: 10 + +
  • + +
    + +#### 1.1.2 Strings in Python +

    For more detailed introduction on strings, please visit -strings in Java.

    Examples in Python:

    @@ -961,9 +1011,11 @@ summary = "Order of Growth">Data Structures and Algorithms 1.

    ## 6 Object-Oriented Programming +### 6.1 Object-Oriented Programming in Python +

    For more information about the details of Object-Oriented -Programming, refer to +Programming, refer to Object-Oriented Programming in C++.

    @@ -1032,6 +1084,32 @@ print(a.balance) # 50 +### 6.2 Inheritance + +

    For more information about inheritance, please visit +Object-Oriented Programming in C++.

    + +### 6.3 Special Method Functions + +

    Certain names are special because they have built-in behavior.

    + +

    These names always start and end with two underscores.

    + + +
  • __init__ Method invoked +automatically when an object is constructed
  • +
  • __repr__ Method invoked +to display an object as a Python expression
  • +
  • __add__ Method invoked +to add one object to another
  • +
  • __bool__ Method invoked +to convert an object to True or False.
  • +
  • __float__ Method invoked +to convert an object to a float (real number).
  • +
    + ## 7 Scheme ### 7.1 Scheme Fundamentals