- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program to Create a Class wherein a Method accepts a String from the User and Another Prints it
When it is required to create a class that has a method that accepts a string from the user, and another method that prints the string, object oriented method is used. Here, a class is defined, and attributes are defined. Functions are defined within the class that perform certain operations. An instance of the class is created, and the functions are used to perform calculator operations.
Below is a demonstration for the same −
class print_it(): def __init__(self): self.string = "" def get_data(self): self.string=input("Enter the string : ") def put_data(self): print("The string is:") print(self.string) print("An object of the class is being created") my_instance = print_it() print("The 'get_data' method is being called") my_instance.get_data() print("The 'put_data' method is being called") my_instance.put_data()
An object of the class is being created The 'get_data' method is being called Enter the string : janewill The 'put_data' method is being called The string is: janewill
- A class named ‘print_it’ class is defined, that has functions like ‘get_data’, and ‘put_data’.
- These are used to perform operations such as get data from user and display it on screen respectively.
- An instance of this class is created.
- The value for the string is entered, and operations are performed on it.
- Relevant messages and output is displayed on the console.
- Python program to create a dictionary from a string
- Python Program that prints the rows of a given length from a matrix
- C Program that receives a number and prints it out in large size
- Python Program to Create a Class and Get All Possible Subsets from a Set of Distinct Integers
- Create a tuple from string and list in Python
- Python Program to Create a Class and Compute the Area and the Perimeter of the Circle
- Python Program to Create a class performing Calculator Operations
- Java Program to create a BigDecimal from a string type value
- How to create a tuple from a string and a list of strings in Python?
- How to access the members of a class from another class in Java?
- Java Program to create a boolean variable from string
- Golang Program to Create a Class and Compute the Area and Perimeter of a Circle
- Program to create a lexically minimal string from two strings in python
- Java Program to Insert a string into another string