x

Python Input and Output version2

PREV     NEXT

What is Output?

Output is nothing but displaying the data on the monitor or any output device, then we can call it as output.


What is Input?

Input is nothing but reading the data from the keyboard or any input devices, then we can call it as input.

Output:

  • Python 2.x version is not supported in python 3.x version
  • “print” function can be used for displaying the data on monitor or console

Below are the different ways we can use print function

  • The basic syntax for print function is “print ‘statements’. print syntax is used to print the every statement in new line.

  • Below is the syntax to print the multiple statements in single line. To print the multiple statements, we need to separate each statement with comma ‘,’

  • To print the different types of variables and constants,

  • To Print the variable data with respect to format specifier,


Input:

  • Python 2.x version is not supported in python 3.x version
  • Python 2.x Version has two variants of input functions. They are,
  1. raw_input ()
  2. input ()

1. raw_input():

raw_input() function takes argument as string and then it will return string on prompt.

Example:

raw_input(“string”)

  • By default it will return string. So, if you want store data in variable, then it will store as a string.

  • Below is the syntax to read the numbers.

2. input ():

input() function is also used to read the input from the keyboard. But, the difference between raw_input() and input() functions is, variable will be considered as string by default even if it’s not type casted in raw_input(). But, in input(), it will be type casted automatically with respect to input.

PREV     NEXT



Like it? Please Spread the word!