Answers for "python self"

14

classes in python with self parameter

self represents the instance of the class. By using the “self” keyword we can access the attributes and methods of the class in python. It binds the attributes with the given arguments.
Posted by: Guest on April-26-2020
0

python class definition reminder

class Mapping:
    def __init__(self, iterable):
        self.items_list = []
        self.__update(iterable)

    def update(self, iterable):
        for item in iterable:
            self.items_list.append(item)

    __update = update   # private copy of original update() method

class MappingSubclass(Mapping):
	# MappingSubclass inherits methods and attributes from Mapping
    def update(self, keys, values):
        # provides new signature for update()
        # but does not break __init__()
        for item in zip(keys, values):
            self.items_list.append(item)
Posted by: Guest on March-12-2020
-1

self python

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

  def myfunc(abc):
    print("Hello my name is " + abc.name)

p1 = Person("John", 36)
p1.myfunc()
Posted by: Guest on July-23-2021
-3

python self nedir

'''
Created on 14 Jan 2017
@author: Ibrahim Ozturk
@author: www.ozturkibrahim.com
'''
 
class Musteri(object):
    """Bir banka musterisinin hesabindaki tutari kontrol etme. Musteri sinifi
    asagidaki ozelliklere sahiptir : 
    Ozellikler:
        isim   : Musteri ismini tutan string turunde parametre
        bakiye : Musterinin hesabinda halihazirdaki bakiyeyi gosteren float tipinde parametre. 
    """
 
    def __init__(self, isim, bakiye=0.0):
        """Girilen isim ile ve baslangic bakiyesi olarak sifiri koyan musteriyi olusturur."""
        self.isim    = isim
        self.bakiye  = bakiye
 
    def paraCek(self, tutar):
        """Hesaptan ilgili tutarin cekilmesinin ardindan yeni bakiyeyi doner."""
        if tutar > self.bakiye:
            raise RuntimeError('Bakiye yetersiz.')
        self.bakiye -= tutar
        self.bilgiGoster()
        return self.bakiye
 
    def paraYatir(self, tutar):
        """Hesaba ilgili tutarin yatirilmasinin ardindan yeni bakiyeyi doner.."""
        self.bakiye += tutar
        self.bilgiGoster()
        return self.bakiye
     
    def bilgiGoster(self):
        """Ilgili musterinin ismini ve hesap bakiyesini ekrana basar.."""
        print(self.isim + " isimli musteriye ait bakiye >> " + str(self.bakiye) + " TL'dir.")
     
musteri1 = Musteri('Ibrahim Ozturk', 500.0)
musteri1.paraCek(100.0)
Posted by: Guest on March-06-2021

Python Answers by Framework

Browse Popular Code Answers by Language