Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
@ltagliaferri, hi there:
# how ridiculous is it?
class Shark:
def __init__(self, *args):
self.name = args[0]
self.age = args[1]
def main():
user = Shark('jack', 'young')
print(user.name, user.age, sep = ' || ')
user.__init__('conor', user.age)
print(user.name, user.age, sep = ' | ')
if __name__ == "__main__":
main()
Thank you Lisa. Tutorials on Digital Ocean are among the clearest, most elegant, and most to the point. Your tutorial should be an example in clear thinking and communication.
Haaaaaaaaaaaa teacher,why the class name has no opening and closing curve brackets ?.Great content ,explained in very easy and simple words.👍
When you create an object out of the class, you use the brackets, but when you define a new class name, you do not use brackets.
However, I understand why you asked that question. According to this site: http://www4.ncsu.edu/~kaltofen/courses/Languages/PythonExamples/python-lectures/_build/html/lectures/three.html:
class Name('object') is preferred over class Name because the author of that site claims the latter will not work in Python 3.X (3 or above). I ran a sample code using both styles and had no problems–that is, both work. But Python Zen dictates there be only ONE way to do something in Python, and ‘simple is better than complex’, hence the no brackets version makes sense at least from the point of view of readability and programmer efficiency.
More concretely:
Here is when we define a new class called Food:
class Food:
def __init__(self, name, taste, price, size):
self.name= name
self.taste = taste
self.price = price
self.size = size
Now Food is too general. Suppose I order some Food. I cannot say I want Food to the waitress, right? so I create a food object but this time I need brackets for the class name:
pizza = Food()
But this is not very helpful. What kind of pizza did I have in mind?
pizza = Food("Margarita", "spicy", 20, 18)
So an 18-inch spicy Margarita for 20$. Thus, including brackets when we created a new object out of the general class was holding all that info inside it, whereas the original name of the class when we began to define it does not cause confusion and can be written without the brackets–especially to differentiate it from a function (as functions need brackets for their arguments).
My method is like this. If am I right or wrong?
class Mobile: def init(self,name,model): self.name = name self.model = model
class MobileStore: def init(self): self.mobiles = []
def add_mobile(self,new_mobile):
if isinstance(new_mobile,Mobile): #new_mobile argument is the instance of Mobile class and this argument as class
self.mobiles.append(new_mobile)
else:
raise TypeError('new mobile should be object of Mobile class')
oneplus = Mobile(‘one plus 6’, ‘s9’)
mobostore = MobileStore()
mobostore.add_mobile(oneplus) mobophones = mobostore.mobiles print(mobophones[0].model)