This notebook demonstrates multiple creative ways to print "Hello, World!" in Python
1️⃣ Classic Print
The standard and most common way to print text in Python. print("Hello, World!") Hello, World!2️⃣ Single Quotes
Python allows both single and double quotes for strings. print('Hello, World!') Hello, World!3️⃣ Using a Variable
Store the message in a variable before printing. msg = "Hello, World!" print(msg) Hello, World!4️⃣ String Concatenation
Combine multiple strings using the + operator. print("Hello, " + "World!") Hello, World!5️⃣ Using join()
Join multiple strings from a list into one string. print("".join(["Hello", ", ", "World!"])) Hello, World!6️⃣ f-String
Use formatted string literals (modern and recommended way). text = "World" print(f"Hello, {text}!") Hello, World!7️⃣ format() Method
Older but still widely used string formatting method. print("Hello, {}!".format("World")) Hello, World!8️⃣ Using sep Parameter
Customize how print separates multiple values. print("Hello", "World!", sep=", ") Hello, World!9️⃣ List Unpacking
Unpack list elements directly into print function. print(*["Hello,", "World!"]) Hello, World!๐ Using ASCII Values
Construct the string using ASCII character codes.print(chr(72)+chr(101)+chr(108)+chr(108)+chr(111)+",
"+chr(87)+chr(111)+chr(114)+chr(108)+chr(100)+"!") Hello, World!
1️⃣1️⃣ Lambda Function
Print using an anonymous (lambda) function. (lambda x: print(x))("Hello, World!") Hello, World!1️⃣2️⃣ sys.stdout.write()
Directly write output to standard output stream. import sys sys.stdout.write("Hello, World!") Hello, World!๐น import sys
sys is a built-in Python module.
It provides access to system-level functions and variables.
One important object inside it is stdout.
Think of it like this:
sys → system tools
stdout → standard output (your screen / console)
๐น What is sys.stdout?
stdout means standard output stream
It’s where Python sends output by default
When you use print(), Python internally writes to sys.stdout


0 Comments:
Post a Comment