Python

Constant dripping wears away a stone

Input and Output


Printis a reserved word in Python that is used to print results or messages to the screen or any other standard output device.
  • Output:

    To print a message (a string), enclose the message in single quotation marks or double quotation marks. To output the value of a variable, for example, to print the value of the variableresult,simply useprint(result). To print more than one value with one print statement, separate the values with a comma. For example:

    • print("Hello World!"):Print the messageHello Worldto the screen.
    • result = 3, print(result): 3 is written to the screen.
    • result2 = 4, print(result, result2): 3 4 is written to the screen.
    • line break \n, tab stop \t:\n is a line break; \t is a tab stop.
  • Input([prompt]):

    This Python built-in function takes input from users and returns it. By default, this function is to read a string. If you are reading another type, you need to convert the string that you get from the input statement to that type.

    • prompt: An optional parameter. It is a string that is written to the screen or other standard output device without trailing the newline.
    • name = input("Enter your name:"): The string "Enter your name" is a prompt written to the screen. The computer will be waiting for you to enter something for your name. After you finish entering the name, press the "Enter" key on the keyboard. The input that you entered will then be assigned to the variablename.
    • float(input()): Take the string returned from the input() method and convert it into a float.
    • int(input()): Take the string returned from the input() method and convert it into an int.