Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

object function in Python

class Student:
	def __init__(self, name, gpa, major):
    self.name = name
    self.gpa = gpa
    self.major = major
    
   	def is_good_student(self):
    	if self.gpa > 3.2:
        	return True
        else:
        	return False
Comment

what is an object in python

#objects are collections of data
Comment

class method in python

# Python program to demonstrate
# use of a class method and static method.
from datetime import date
  
class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age
  
    # a class method to create a
    # Person object by birth year.
    @classmethod
    def fromBirthYear(cls, name, year):
        return cls(name, date.today().year - year)
  
    # a static method to check if a
    # Person is adult or not.
    @staticmethod
    def isAdult(age):
        return age > 18
  
person1 = Person('mayank', 21)
person2 = Person.fromBirthYear('mayank', 1996)
  
print(person1.age)
print(person2.age)
  
# print the result
print(Person.isAdult(22))
Comment

object python

# ---------------------------------------- Object Oriented Programming ------------------------------------- #
# It Is Based On Three Pillars =  Encapsulation = ( self ) / -  Inheritance / -  Polymorphism /
# Constructor ==> __init__(self) / self => Default Parameter // Self Can Be Named AnyThing You Need 
# Class ==> / Like The Real Class And You Putted Inside Her Somethings Like = ( Constructor, Methods, Attributes ) 
# print( classname.__class__ ) ==> / If You Need To Know THe Class Follow What ? 
# If You Wanna Run The Class You Need To Call Her In Variable = ( x = ClassName 
 x.Thing )
# Inheritance ==> / If You Have Class In Your Project And You Wanna Put In Something
#  You Create The New Class And Give Her The Class Name You Need As A Parameter 
# Polymorphism Take The Same Elements From The Inheritance But Do Something Deference Or Any Some Like
#  ==> + Between The Numbers Do Addition But Between Strings Do Concatenation
# super() ==> If You Need Inheriting A Constructor From Another Class :-
#   You Need Use super() Method / :-
#   You Type InSide Your Class Under You //> __Init__( self, What You Need Inheriting From Old Class ) :
#         super( Your Class, self ).__init__( What You Need Inheriting From Old Class, And Your New Additions ) :
#         If you Need Addition Something Like :
#           print( "Hello, Im From 'Super'" )
# Inheriting From Class Or More :-
#   If We Have 4 Class A,B,C,D 
#       A Inside Her Function Do ==> ( "Doing From 'A'" )
#       B Inheriting From A
#       C Inside Her Function Do ==> ( "Doing From 'C'" )
#       D Inheriting From B,A
# If We Run The Function Inside D Will Print ==> Doing From 'A'
# Because He Start From 'B' Because 'B' The First Class 'D' Inheriting From, After This Go 
# To 'A' // Because 'B' Inheriting From 'A'  Will Print => Doing From 'A' /
# If If He Does Not Find Anything In 'A'
# He Back And Go To 'C'
# If You Need Know The Way Just Type ==> print( TheClassName.mro() )
Comment

PREVIOUS NEXT
Code Example
Python :: alphabeticallly 
Python :: pandas and operator 
Python :: python create list of empty lists 
Python :: how to encrypt and decrypt strings python 
Python :: telegram bot documentation python 
Python :: position text in a box matplotlib 
Python :: detect if usb is plugged in python 
Python :: pandas data frame from part of excel better example 
Python :: how to create image folder in numpy aray 
Python :: pyton como identificar se é numero 
Python :: run python script task scheduler 
Python :: powershell bulk rename and add extra string to filename 
Python :: pandas split column fixed width 
Python :: how to interrupt a loop in python 
Python :: how to connect ip camera to opencv python 
Python :: how to use histogram in python 
Python :: How to plot Feature importance of any model in python 
Python :: count unique values in python 
Python :: ope pickle file 
Python :: multithreaded programming in python 
Python :: reverse string in python without using function 
Python :: django-storages delete folder 
Python :: sum of fraction numbers in python 
Python :: cin python 
Python :: matplotlib yaxis off 
Python :: python popen 
Python :: filtering certain rows in python that contains a part of string 
Python :: python get website chrome network tab 
Python :: Converting categorical variable to numeric variable in python 
Python :: come fare aprire una pagina web python 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =