The following is an example of how Python calls object properties or methods through strings. It has a good reference value and I hope it will be helpful to everyone. Let’s take a look together
Sometimes you need to pass in properties or methods as parameters. At this time, you can call object properties or methods with strings in the following ways
1. eval
##
1 2 3 |
|
1 2 |
|
2. getattr
1 2 3 |
|
1 2 |
|
3. Use the built-in library operator
1 2 3 |
|
1 2 |
|
Summary of several ways to connect python strings
How to convert python strings into two-dimensional arrays
The above is the detailed content of Python calls object properties or methods through strings. For more information, please follow other related articles on the PHP Chinese website!