Print in Python
This is a simple tutorial to printing data in the Python programming language.
Steps
- Work out which python you are running. Macs and Linux come with Python 2 installed but you've installed it yourself or are on a Windows machine, it may be Python 3. When you open a Python shell (via the IDLE development tool that comes with Python) or by typing python into the terminal on Mac, the version number of the Python being used will be displayed.
- Type in print followed by a space then whatever you wish to be printed. If you are using Python 3 putting brackets around the thing to be printed is required.
- If you wish to combine multiple items to be printed at once, use the + sign to add them together, and the str() function to convert them before addition (put the item to be converted in the brackets).
Tips
- Combining items of different types: print (str(9000) + " is an integer value.")
- Python 3: print ("Hello World!")
- Python 2: print "Hello World!"
- Combining items: print ("Python is " + "easier than C!")
- You can also combine items by using a comma: print("Hello", "World") would output Hello World.
Related Articles
- Create a Very Simple Program in Python
- Write a Hello World Program in Python
- Start Programming in Python
- Use Python List Comprehension
- Make a Quiz Game in Python
- Create Loops in Python