- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the return value from a function in a class in Python?
The following code shows how to get return value from a function in a Python class
Example
class Score(): def __init__(self): self.score = 0 self.num_enemies = 5 self.num_lives = 3 def setScore(self, num): self.score = num def getScore(self): return self.score def getEnemies(self): return self.num_enemies def getLives(self): return self.num_lives s = Score() s.setScore(9) print s.getScore() print s.getEnemies() print s.getLives()
Output
9 5 3
- Related Articles
- How to return a value from a JavaScript function?
- How to return an object from a function in Python?
- How to return a JSON object from a Python function in Tkinter?
- How to return a json object from a Python function?
- Get a value from Quartet class in JavaTuples
- Get a value from Triplet class in JavaTuples
- Get a value from Unit Tuple class in Java
- Get a value from Pair Tuple class in Java
- How to call a parent class function from derived class function in C++?
- How can we return a dictionary from a Python function?
- How to return void from Python function?
- How to return variable value from jQuery event function?
- How can a Python function return a function?
- Is it required to have a return a value from a JavaScript function?
- How to return an array from a function in C++?

Advertisements