Green
0
Q:

How to make a new class in python

#Use the class function and give the class a name
#next use the def __init__() to initilaize and give it some properties.
class Fruits():
  def __init__(self, name, colour, taste):
    self.name = name
    self.colour = colour
    self.taste = taste
#Now create an object by first calling the class
fruit1 = Fruits(apple, red, sweet)
print(fruit1.name)
#this will print the name which is apple
print(fruit1.colour)
#this will print the colour which is red
print(fruit1.taste)
#this will print the taste which is sweet
0
class Person:
  def __init__(self, name, age):
    self.name = name
    self.age = age

p1 = Person("John", 36)

print(p1.name)
print(p1.age)
1

class Person:
  def __init__(self, name, age):
    self.name = name
    self.age = age

p1 = Person("John", 36)

  
print(p1.name)
print(p1.age) 
0

New to Communities?

Join the community