string representation of object python

Solutions on MaxInterview for string representation of object python by the best coders in the world

showing results for - "string representation of object python"
Leonard
11 Jul 2017
1#!/bin/python3
2
3import math
4import os
5import random
6import re
7import sys
8
9class Car:
10    def _init_(self,speed,unit):
11        self.speed=speed
12        self.unit=unit
13    def __str__(self):
14        return "Car with the maximum speed of {} {}".format(self.speed,self.unit)  
15
16class Boat:
17    def _init_(self,speed):
18        self.speed=speed
19    def __str__(self):
20        return "Boat with the maximum speed of {} knots".format(self.speed)  
21
22