Python Classes - Web Development and Design | Tutorial for Java, PHP, HTML, Javascript Python Classes - Web Development and Design | Tutorial for Java, PHP, HTML, Javascript

Breaking

Post Top Ad

Post Top Ad

Saturday, December 1, 2018

Python Classes

Python Classes


Classes

A class defines the behavior of  an object and  the kind of  information an object can store. The  information in a class is stored in attributes, and functions that belong to a class are called methods from its parent class.


#Creating a dog class 
class Dog():
 """Represent a dog."""

 def __init__(self, name):
  """Initialize dog object."""
  self.name = name

 def sit(self):
  """simullate sitting."""
  print(self.name + " is sitting.")

my_dog = Dog('peso')

print(my_dog.name + " is a great dog!")
my_dog.sit()

#Inheritance
class SARDog(Dog):
 """Represent a search dog."""
 def __init__(self, name):
  """Initialize the sardog."""
  super().__init__(name)

 def search(self):
  """Simulate searching."""
  print(self.name + " is searching.")

my_dog = SARDog('wiillie')

print(my_dog.name + " is a search dog.")
my_dog.search()

Screenshot

python class

 

1 comment:

  1. worldwide man-made reasoning business sector was esteemed at US$126.24 bn in 2015 and is anticipated to reach US$3,061.35 bn by 2024.artificial intelligence course

    ReplyDelete

Post Top Ad