In this article, we are going to learn how to use print() and sys.stdout.write() methods to write python program to print string.

Above image depicts how use built-in methods (input() or sys.stdin.read()) to take input and store in variable. Then, print that variable using another built-in method (print() or sys.stdout.write()).
Methods we are going to learn –
- Using print() method
- Using sys.stdout.write() method
Method 1: Using print() method to Print String
We can using print() method as below –
s = input ( "Enter string value: " ) |
print ( "Entered string: " , s) |
Here, we write string to console using print() method.
When you run above program, output is –
Method 2: Using sys.stdout.write() method to Print String
sys.stdout.write() is present inside sys module in python. We can use it as below –
s = input ( "Enter string value: " ) |
sys.stdout.write( "Entered string: " + s) |
When you run above program, output is –
Entered string: Hi Tutorialwing! |
That’s how we write python program to print string value.
You must be logged in to post a comment.