__init__


Definition
Special method initiates def function.

Syntax
__init__

Parameters
N/A

Examples

class...: def:.....:str.capitalize()
The class return after capitalizing the strings.
 class string_capitalize:
    def __init__(self,a,b):

        self.a=str.capitalize(a)
        self.b=str.capitalize(b)
        print(a, b)
        

x="python"
y="lake"

string_capitalize(x,y)



>>> 
Python Lake
>>> 

class.....: def__init__():..... str.upper
The function returns with capitalizing the strings.
 class string_upper:
    def __init__(self,a,b):

    
            print(str.upper(a), str.upper(b))
        
x=input("Please enter your first name: ")
y=input("Please enter your second name: ")


string_upper(x,y)

>>> 
Please enter your first name: Adil
Please enter your second name: Waseeem
ADIL WASEEM
>>>


class.....: def __init__()......:....str.isidentifier().....str.lower()....str.isapha()
The function tested whether the string value is single word, or contain non-string values through input().
 class str_methods():
    def __init__(self, a,b,c):

        identifier=str.isidentifier(a)

        if str.isidentifier(a).__eq__(True):
            print("Full name should not contain special characters or numbers")
            
        else:
            print("Your full not name accepted")

        
      
        alpha=str.isalpha(b)
        
        if alpha.__ne__(False):
            print("Full name accepted")

            lower=str.lower(c)
            if lower.__eq__(str.lower(c)):
                 str.upper(c)
                 print("System convert your name to uppercase:", str.upper(c))
            else:
                 print("Your name accepted")

        else:
            print("Full name can't be one word")

                    

input_text=input("Please enter  your full name: ")

str_methods(input_text, input_text,input_text)
    
          

>>> 
Please enter your full name: Adil22
Full name should not contain special characters or numbers
Full name can't be one word
>>>        


class....: def....: str.find()...str.count
The function allow the user to find word in their text.
 class method_text_finder():
    def __init__(self, a,b):

        self.a=str(a)
        find1=a.find(b)
        print("The word found in your text at position:",find1+1)

        count1=a.count(b)
        print("The total word found in your text:",count1)

text=input("Please enter your text: ")
find_word=input("Please enter your text:")

method_text_finder(text,find_word)

>>> 
Please enter your text: Python Research Centre is located at Woodbridge Va
Please enter your text:Woodbridge
The word found in your text at position: 38
The total word found in your text: 1
>>> 


class.....: def....: str.count()
The function find the number of vowels in the name through input() through str.count().
 class string_methods:
    def __init__(self,a,b):

         
        va=a.count("a")
        ve=a.count("e")
        vi=a.count("i")
        vo=a.count("o")
        vu=a.count("u")
        

        count_a=va+ve+vi+vo+vu

        print("Total vowels in your first name are:",count_a) 

        va=b.count("a")
        ve=b.count("e")
        vi=b.count("i")
        vo=b.count("o")
        vu=b.count("u")
        

        count_b=va+ve+vi+vo+vu

        print("Total vowels  in your last name :",count_b)


        print("Total vowels in your full name:", count_a+count_b)
        
        
first_name=input("Please enter your first name: ")
second_name=input("Please enter your second name: ")


string_methods(first_name,second_name)


>>> 
Please enter your first name: adil
Please enter your second name: waseem
Total vowels in your first name are: 2
Total vowels in your last name : 3
Total vowels in your full name: 5
>>>


class......: def__init__():......str.upper
The method return with the value of box.
 class box:
    def __init__(self, h, w):
        self.x = h
        self.y = w
z = box(3.0, -4.5)
z.x*z.y
print(z.x*z.y)

>>> 
-13.5
>>> 


def__init__()
The method return with the round() value of the parameter.
class round_value:
    def __init__(self,a):
        self.x = round(a)
        
value=33.22
z=round_value(value)
output=z.x

print(output)

>>> 
33
>>> 


class method executed the if statement about accumulated value of value1 and value2.
 import operator
class add_value:
    def __init__(self,a,b):
        self.a=a
        self.b=b
        self.c=a+b
        if self.c.__lt__(20):
            print("The values added are more than required parameters:",self.c)
        else:
            print("Values added: ", self.c)
                  
                
value1=33
value2=33.1

add_value(value1, value2)

>>> 
Values accepted: 66.1
>>>

class....: def __init__()
The class method return the complex values and tested the equality of the values.
 class complex_value:
    def __init__(self, a,b,c):

        self.a=complex(a).conjugate()
        self.b=complex(b).imag
        self.c=complex(c).real

        print("The comlex conjugate value of a is: ",self.a)
        print("The complex imag value of b is: ",self.b)
        print("The complex  real value of c is: ",self.c)
        
        if self.a.__eq__(complex(a).conjugate()):
            print("The value of a is equal to complex(a) conjugate")
        else:
             print("The value of a is NOT equal to complex(a) conjugate")
            

        if self.b.__eq__(complex(b).imag):
            print("The value of b is equal to complex(b) imag")
        else:
            print("The value of b is NOT equal to complex(b) imag")


        if self.c.__eq__(complex(c).real):
            print("The value of c is equal to complex(c) imag")
        else:
            print("The value of c is NOT equal to complex(c) imag")

           
value1=81
value2=222
value3=33
complex_value(value1,value2, value3)

>>> 
The comlex conjugate value of a is: (81-0j)
The complex imag value of b is: 0.0
The complex real value of c is: 33.0
The value of a is equal to complex(a) conjugate
The value of b is equal to complex(b) imag
The value of c is equal to complex(c) imag
>>>


class....: def __init__():
There simple mainloop widget(). 
import tkinter
class maintloop1():
    def __init__(self,a):
        self.a=a
        a.mainloop()

x=tkinter.Tk()
maintloop1(x)




Comments