Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbd5a9c3

Browse files
authored
Merge pull requestwilfredinni#377 from HasnatHridoy/master
Update getattr.md
2 parentsb9fc3a7 +235456e commitbd5a9c3

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

‎docs/builtin/getattr.md‎

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,36 @@ Python getattr() built-in function
1616
</base-disclaimer-content>
1717
</base-disclaimer>
1818

19-
<!-- remove this tag to start editing this page-->
20-
<empty-section />
21-
<!-- remove this tag to start editing this page-->
19+
##Syntax
20+
21+
```python
22+
getattr(object, name)
23+
```
24+
or
25+
```python
26+
getattr(object, name, default)
27+
```
28+
-`object`: The object whose attribute you want to access.
29+
30+
-`name`: The name of the attribute you want to retrieve.
31+
32+
-`default`: (Optional) The value to be returned if the attribute is not found. If not provided,`None` is returned.
33+
34+
##Example
35+
36+
```python
37+
classExample:
38+
attribute="Hello, World!"
39+
40+
# Creating an instance of the class
41+
obj= Example()
42+
43+
# Using getattr to access the attribute
44+
value=getattr(obj,'attribute','Nothing found')
45+
46+
print(value)# Output: Hello, World!
47+
48+
# If the 'attribute' does not exist then 'Nothing found' will be printed.
49+
```
50+
51+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp