print()
Use to print output / result on our console.
Usage
Syntax:
python
print()Simple usage
Code:
print.py
python
print("Hello, World!")
print("This is a simple print statement in Python.")
print(1234)Result:
Hello, World!
This is a simple print statement in Python.
1234Output multiple content
- can use
+or,to join multiple content
python
name = "Alice"
print("Hello, " + name + "!")
print("Hello,", name, "!")Output:
Hello, Alice!
Hello, Alice !INFO
- For more other string joining method, refer here.
Print and break a line
- use
\nend of the""of aprint()
py
print("Hello World \n")
print("This has a line blank on above")Results:
Hello World
This has a line blank on abovePrint continuosly without a line break
- add
end=""params to replace"\n"by default.
py
print("Hello")
print("World")
print("Hello", end="")
print("World")Results:
Hello
World
HelloWorldBox Drawing
By using \t as a escape character that represents a horizontal tab
\tis great for quick console formatting
py
print("Name\tAge\tCity")
print("Alice\t25\tNew York")
print("Bob\t30\tLondon")Results:
Name Age City
Alice 25 New York
Bob 30 London