1. Home
  2. Data Science
  3. Python
  4. Which of the following is the correct way to print "Hello…

Added 27 Jan 2024

Which of the following is the correct way to print "Hello, world!" in Python?

  1. System.out.println("Hello, world!")
  2. print("Hello, world!") Correct answer
  3. echo("Hello, world!")
  4. cout << "Hello, world!" << endl;

Correct answer

B. print("Hello, world!")

16 views

MCQSEXAM

Explanation

print("Hello, world!") is correct. In Python 3 print is a built-in function, so parentheses are required.

The other options come from other languages: System.out.println is Java, echo is PHP and shell, and cout << is C++.

For more solved questions like this one, see Computer Science MCQs on MCQsExam.com.

Doubts & discussion

Not sure why the answer is B? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Python MCQs

Practise all Python MCQs

Similar MCQs