UrbanPro

Learn Python Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

How do I make a Python class act like an instance?

Asked by Last Modified  

Follow 1
Answer

Please enter your answer

Maths tutor with 7 years experience

I would like to create a class that, when I call without the double brackets, returns a value in any context, just like what str or int does. For example, what can I do to make this possible: >>> class color: ... def __init__(self, r, g, b): ... self.r = r ... self.g...
read more

I would like to create a class that, when I call without the double brackets, returns a value in any context, just like what str or int does. For example, what can I do to make this possible:

>>> class color:...     def __init__(self, r, g, b):...         self.r = r...         self.g = g...         self.b = b...     def whatever_it_is(self):...         return (self.r, self.g, self.b) # Class returns tuple>>> myColor = color(16, 32, 64)>>> myColor.g32>>> myColor(16, 32, 64)>>> color(5, 68, 37)(5, 68, 37)
read less
Comments

Related Questions

Who can learn the Python?

Anyone can learn python doesn't require any programming knowledge (or) experience. Python is much easier as compared to other programming languages. Python is easy to learn. The learning curve is very gradual.
Sunil
Are there coding standards or a style guide for Python programs?
The PEP 8 -- Style Guide for Python Code provides a fairly comprehensive list of Python naming conventions. Here are a few examples, but you should consult the PEP 8 style guide for more detailed information...
A
0 0
7
What are the best learning sites for Python?
w3school, toturialpoint, leetcode is best for practice,CodeCademy, Udemy,Coursera
Apoorva
1 0
6

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons


Simulation of a die-roll:Usage of random module
Task:Simulation of a simple die-rolling game,where we keep rolling a six-sided die until we have rolled a total of 20. To simulate a six-sided die roll, we need a way to generate a random integer between...


Built-In Functions (Python)
Built-in Functions: The Python interpreter has a number of functions built into it that are always available. They are listed here in alphabetical order. Built-in Functions abs() divmod() input() open() staticmethod() all() enumerate() int() ord() str() any() eval() isinstance() pow() sum() basestring() execfile() issubclass() print() super() bin() file() iter() property() tuple() bool() filter() len() range() type() bytearray() float() list() raw_input() unichr() callable() format() locals() reduce() unicode() chr() frozenset() long() reload() vars() classmethod() getattr() map() repr() xrange() cmp() globals() max() reversed() zip() compile() hasattr() memoryview() round() __import__() complex() hash() min() set() ...

Decorator Introduction
A decorator takes in a function, adds some functionality and returns it. Functions can be passed as arguments to another function like map, filter and reduce Function that take other functions as arguments...

Recommended Articles

Python is one of the most popular programming languages in the world. It is general-purpose, object oriented, high-level programming language used in a number of programming fields. Python is a great programming language to learn as it will introduce you to the world of programming. If you are from the technical background...

Read full article >

Applications engineering is a hot trend in the current IT market.  An applications engineer is responsible for designing and application of technology products relating to various aspects of computing. To accomplish this, he/she has to work collaboratively with the company’s manufacturing, marketing, sales, and customer...

Read full article >

Business Process outsourcing (BPO) services can be considered as a kind of outsourcing which involves subletting of specific functions associated with any business to a third party service provider. BPO is usually administered as a cost-saving procedure for functions which an organization needs but does not rely upon to...

Read full article >

Hadoop is a framework which has been developed for organizing and analysing big chunks of data for a business. Suppose you have a file larger than your system’s storage capacity and you can’t store it. Hadoop helps in storing bigger files than what could be stored on one particular server. You can therefore store very,...

Read full article >

Looking for Python Training classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Python Training Classes?

The best tutors for Python Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Python Training with the Best Tutors

The best Tutors for Python Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more