Program for accepting string from Keyboard and displaying

Program to accept input from keyboard and display on the screen.

Use input() function to accept data from keyboard and assigned it to a variable str.

str = input('Enter any string: ')

Displaying the value of variable str on screen using print()

print(str)

Output

Enter any string: Hi This is Python Programming Language
Hi This is Python Programming Language

Complete code

str = input('Enter any string: ')
print(str)

Code 2 : Accepting input from keyboard and applying tab at the beginning of the string

Use input() function to accept data from keyboard

str = input('Enter any string: ')

Create a string variable and assign value \t escape character

a = '\t'

Display output using below print() statement

print(a,str)

Output

Enter any string: Hi This is the example of using escape characters
	 Hi This is the example of using escape characters

Above code add spaces at the beginning of the string.

Complete Code

str = input('Enter any string: ')
a = '\t'
print(a,str)

Advertisement

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s