using print and input function in python3 in different ways


Printing in python 3

To output your data to the screen, use the print() function. You can write print(argument) and this will print the argument in the next line when you press the ENTER key.

as you can see in image above 
in python 3 to print hello world we just have to write print('hello world') 
>>>print(1,2,3)
1 2 3
You can separate the output using the comma delimiter. By default, this adds a space between the output items. For example, the sequence of numbers 1,2,3 separated by comma , gets printed with a space between one number and the next.
To change the output to what you want, use the keyword arguments sep and end to print ( ). When separating the output with a comma delimiter, you can also define the separation format using the 
sep keyword
>>>print(1,2,3,sep='|')
1|2|3
>>>print(1,2,3,end='the end')
1 2 3the end
to print to next line use escape sequence '\n'
>>>print(1,2,3,sep='\n')
1
2
3

Taking input in python 3 

A function is defined as a block of organized, reusable code used to perform a single, related action. Python has many built-in functions; you can also create your own. Python has an input function which lets you ask a user for some text input. You call this function to tell the program to stop and wait for the user to key in the data. In Python 2, you have a built-in function raw_input(), whereas in Python 3, you have input(). The program will resume once the user presses the ENTER or RETURN key. Look at this example to get input from the keyboard using Python 2 in the interactive mode. Your output is displayed in quotes once you hit the ENTER key.

  

Comments

Post a Comment