zoukankan      html  css  js  c++  java
  • Attributes

    You can assign values to an instance using dot notation. This syntax for selecting a variable from a module, such as math.pi or string.uppercase. In this case, though, we are assigning values to named elements of an object. These elements are called attributes. The following diagram shows the result of these assignments. A state diagram that shows an object and its attributes is called an object diagram:

                             

    The variable blank refers to a Point object, which contains two attributes. Each attribute refers to a floating-point number. The expression blank.x means, ‘Go to the object blank refers to and get the value of x’. In this case, we assign that value to a variable named x. There is no conflict between the variable x and the attribute x. You can use dot notation as part of any expression. And you can pass an instance as an argument in the usual way. For example:

     

    Inside the function, p is an alias for blank, so if the function modifies p, blank changes.

    from Thinking in Python

  • 相关阅读:
    《需求分析与系统设计》第二篇阅读体会
    《需求分析与系统设计》第一篇阅读体会
    《编写有效用例》第二篇阅读体会
    项目目标文档
    字符流
    字节流
    递归
    File类
    JDBC接口和工具类
    异常
  • 原文地址:https://www.cnblogs.com/ryansunyu/p/3992824.html
Copyright © 2011-2022 走看看