Text output

we can output to the terminal with print function. In this article we’ll show you how to
output text to the screen with Python.

Related Courses:

Output

To output text to the screen you will need one line of code:

If you run the program:

Hello World

Print newline

To write multiple lines, add the ‘\n’ character:

Results in:

Hello World
This is a message
Note: the characters \n create a new line

 

Print variables

To print variables:

This will show:

3

To print multiple variables on one line:

Will give you:

x = 2, y = 3
Previous Post
Next Post

16 Replies to “Text output”

  1. the code of print multiple variables show be below:
    x = 2
    y = 3
    print(x + ‘ ‘ + y)

    if the last line of the code is
    print(x, ‘ ‘, y)
    the text of output is
    (2, ‘ ‘, 3)
    Please correct it, thank you

  2. I have the NINJA-IDE installed on my windows computer right now and I tried entering the first line shown here with no result when I press run project. Am I doing something wrong or maybe I am just not using it right? I am brand new to this whole thing and could really use a helping hand if anyone would be willing. Thanks in advance and sorry for the long post.

  3. I used “name = input(“Enter your name:”)
    print(name)
    when i input name is number, print is ok, but when i input a char, print error message” name = input(‘Enter your name:’)
    File “”, line 1, in
    NameError: name ‘a’ is not defined”

    why?

  4. There is a problem when you write
    name = input(“What your name”)
    and you must type the string with ” or “”, or else you can get NameError

    • Run your python script as a file, such as ‘python hello.py’.
      Then on windows:

      import os
      os.system('cls') # on windows

      on linux:

      import os
      os.system('clear')

Leave a Reply

Your email address will not be published. Required fields are marked *