Menu
Coddy logo textTech

Print Output

Part of the Fundamentals section of Coddy's R journey — lesson 26 of 78.

You've been using print() throughout this course to display output. Now let's take a closer look at how it actually works.

The print() function displays a value to the console. It works with any data type:

print("Hello, World!")
print(42)
print(TRUE)

Each call to print() outputs on a new line. One thing to notice is that print() shows character strings with quotes around them:

print("Welcome")  # Output: [1] "Welcome"

The [1] you see is R's way of showing the index of the first element. This becomes useful when working with longer outputs, but for now, just know it's part of how R displays results.

You can print the result of an expression directly:

print(5 + 3)   # Output: [1] 8
print(10 > 5)  # Output: [1] TRUE

In the next lesson, you'll learn about cat(), which gives you more control over how your output appears.

challenge icon

Challenge

Easy

Use the print() function to display different data types and the result of an expression.

Complete the following tasks in order:

  1. Print the character string "R Programming"
  2. Print the numeric value 3.14
  3. Print the logical value FALSE
  4. Print the result of the expression 25 - 7
  5. Print the result of the comparison 100 >= 50

Each value should be printed on its own line using separate print() calls.

Cheat sheet

The print() function displays values to the console and works with any data type:

print("Hello, World!")
print(42)
print(TRUE)

Each print() call outputs on a new line. Character strings are displayed with quotes, and R shows [1] before output to indicate the index of the first element.

You can print the result of expressions directly:

print(5 + 3)   # Output: [1] 8
print(10 > 5)  # Output: [1] TRUE

Try it yourself

# TODO: Write your code below
# Use print() to display each value on its own line

# 1. Print the character string "R Programming"

# 2. Print the numeric value 3.14

# 3. Print the logical value FALSE

# 4. Print the result of the expression 25 - 7

# 5. Print the result of the comparison 100 >= 50
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals