Python method chaining ⛓️

Published: 25 January 2021
on channel: Bro Code
24,214
1.1k

Python method chaining tutorial explained

#python #method #chaining

method chaining = calling multiple methods sequentially
each call performs an action on the same object and returns self

class Car:

def turn_on(self):
print("You start the engine")
return self

def drive(self):
print("You drive the car")
return self

def brake(self):
print("You step on the brakes")
return self

def turn_off(self):
print("You turn off the engine")
return self


car = Car()

car.turn_on().drive()
car.brake().turn_off()
#car.turn_on().drive().brake().turn_off()

car.turn_on()\
.drive()\
.brake()\
.turn_off()

Bro Code merch store 👟 :
===========================================================
https://teespring.com/stores/bro-code-5
===========================================================


On this page of the site you can watch the video online Python method chaining ⛓️ with a duration of hours minute second in good quality, which was uploaded by the user Bro Code 25 January 2021, share the link with friends and acquaintances, this video has already been watched 24,214 times on youtube and it was liked by 1.1 thousand viewers. Enjoy your viewing!