Write your class code here data_type1 = DataType(‘Integer’, 1234) print(data_type1.name) print(data_type1.value) print('=====================') data_type2 = DataType(‘String’, ‘Hello’) print(data_type2.name) print(data_type2.value) print('=====================') data_type3 = DataType(‘Float’, 4.0) print(data_type3.name) print(data_type3.value)
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Write a class that for running the following codes:
[You are not allowed to change the code below]
#Write your class code here
data_type1 = DataType(‘Integer’, 1234)
print(data_type1.name)
print(data_type1.value)
print('=====================')
data_type2 = DataType(‘String’, ‘Hello’) print(data_type2.name)
print(data_type2.value)
print('=====================')
data_type3 = DataType(‘Float’, 4.0)
print(data_type3.name)
print(data_type3.value)
Output:
Integer
1234
=====================
String
Hello
=====================
Float
4.0
Subtasks:
- Create a class named DataType with the required constructor.
- Assign name and values in constructor according to the output.
Step by step
Solved in 3 steps with 2 images