Hello World Program in Python

Video Tutorial
FREE
Print Hello World thumbnail
This video belongs to
Python Course for Beginners With Certification: Mastering the Essentials
16 modules
Certificate
Topics Covered

If you ask programmers, what was their first program? Most of them would say the "Hello, World" program.

It is a simple program that prints a Hello, World! message on the screen.

In this article, you will begin your journey into programming by writing the same hello world Program in Python.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Python Program to Print Hello world!

Printing Hello World using print() Function

To print "Hello, World!" using the print() function in Python, we can simply write the following code:

Code:

Output:

Explanation:

When we run this code, it will display "Hello, World!" in the console or output window. The print() function in Python is used to output text or values to the console. In this case, it will output the string "Hello, World!" as the specified text.

Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course

Printing Hello World using sys module

To print "Hello, World!" using the sys module in Python, we can use the sys.stdout.write() function.

Code:

Output:

Explanation:

In this code, we imported the sys module, which provides access to some variables and functions related to the Python interpreter. We use sys.stdout.write() to write the string "Hello, World!" to the standard output. The "\n" is added to print a newline character, which is equivalent to pressing the Enter key.

By using the sys module's stdout object, we can achieve the same result as using the print() function to display "Hello, World!" on the console.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Printing Hello World using String Variable

To print "Hello, World!" using a string variable in Python, we can assign the text to a variable and then use the print() function to display its value.

Code:

Output:

Explanation:

In the above code, we create a variable called message and assign the string "Hello, World!" to it. Then, we use the print() function to display the value of the message variable, which will output "Hello, World!" to the console or output window. Using variables allows us to store and manipulate strings or other types of data before printing them.

Printing Hello World using f-string

To print "Hello, World!" using an f-string in Python, we can use the following code:

Code:

Output:

Explanation:

In this code, we create a variable named message and assign it the value "Hello, World!". We then use an f-string by placing an 'f' before the string and enclosing the variable within curly braces {}. When the code is executed, the value of the message variable is inserted into the string, resulting in the output "Hello, World!" being printed to the console. F-strings provide a concise and readable way to include variables within string literals.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Conclusion

  • The simplest way to print "Hello, World!" in Python is by using the print() function. This function outputs text or values to the console.
  • Another approach is to utilize the sys.stdout.write() function from the sys module. It allows writing directly to the standard output.
  • You can store the "Hello, World!" text in a string variable and then use the print() function to display the value of the variable.
  • An f-string (formatted string literal) provides a concise way to include variables within a string. By using an f-string, you can insert the value of a variable directly into the string when printing.

See Also: