Polymorphism – OOP Python

OOP Python – Polymorphism – Addition operator

num1 = 1
num2 = 2
print('Addition operator used for Adding 2 number: ',num1+num2)
#Addition operator used for Adding 2 number

str1 = "String"
str2 = "Concatenation"
print('Addition operator used to Concatenate 2 strings: ',str1+" "+str2)
# Addition operator used to Concatenate 2 strings

Output: Addition operator used for Adding 2 number:  3
            Addition operator used to Concatenate 2 strings:  
	  String Concatenation

OOP Python – Polymorphism – Using len() function

a_string = 'Hello World'
a_list = ['list','has','four','element']
a_dict = {'id':'some_id','key':'value'}


# using len() function on different data structures
print('length of string: {} : '.format(a_string),len(a_string))
print('length of list: {} : '.format(a_list),len(a_list))
print('length of dictionary: {} : '.format(a_dict),len(a_dict))

Output:
length of string: Hello World :  11
length of list: ['list', 'has', 'four', 'element'] :  4
length of dictionary: {'id': 'some_id', 'key': 'value'} :  2