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

  • 相关阅读:
    python opencv PyQt5
    各大web服务器https的证书文件
    mysql 常用字符串操作
    python 修改字符串中的某一位字符
    python mysql
    小程序
    m4a 转MP3
    安装python 3.7
    树莓派版本信息
    bash 重启后台程序脚本
  • 原文地址:https://www.cnblogs.com/ryansunyu/p/3992824.html
Copyright © 2011-2022 走看看