Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
arianshi
learn-python
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
learn-python
/
src
/
classes
/
test_instance_objects.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
41 lines (32 loc) · 1.5 KB
master
Breadcrumbs
learn-python
/
src
/
classes
/
test_instance_objects.py
Copy path
Top
File metadata and controls
Code
Blame
41 lines (32 loc) · 1.5 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""Class Definition Syntax.
类定义语法 (Class Definition Syntax)
@see: https://docs.python.org/3/tutorial/classes.html#instance-objects
"""
def test_instance_objects():
"""Instance Objects.
Now what can we do with instance objects? The only operations understood by instance objects
are attribute references. There are two kinds of valid attribute names:
- data attributes
- methods.
"""
# 实例对象。
#
# 那么我们能对实例对象做什么呢?实例对象唯一支持的操作就是属性引用。有效的属性名有
# 两种:
# - 数据属性 (data attributes)
# - 方法 (methods)
# DATA ATTRIBUTES need not be declared; like local variables, they spring into existence when
# they are first assigned to. For example, if x is the instance of MyCounter created above,
# the following piece of code will print the value 16, without leaving a trace.
# 「数据属性」不需要声明;它们就像局部变量一样,第一次被赋值时就会自动出现。例如,
# 如果 x 是上面创建的 MyCounter 的实例,下面这段代码将打印出值 16,并且不会留下
# 任何痕迹。
# pylint: disable=too-few-public-methods
class DummyClass:
"""Dummy class"""
pass
dummy_instance = DummyClass()
# pylint: disable=attribute-defined-outside-init
dummy_instance.temporary_attribute = 1
assert dummy_instance.temporary_attribute == 1
del dummy_instance.temporary_attribute
You can’t perform that action at this time.