Home > Backend Development > Python Tutorial > Python print() method

Python print() method

PHPz
Release: 2024-07-19 02:11:50
Original
1298 people have browsed it

Python print() method

Today we are going to see python print statement usage.
Print is used to print the output in the console.

Printing a simple string

print("Hello, World!") # Output: Hello, World!

Printing numbers

print(123) # Output: 123
print(3.14) # Output: 3.14

Printing multiple values

print("The answer is", 42) # Output: The answer is 42

Using formatted strings (f-strings)

name = "Alice"
age = 30
print(f"My name is {name} and I am {age} years old.") # Output: My name is Alice and I am 30 years old.

Printing with different separators and end characters

print("Python", "is", "fun", sep="-") # Output: Python-is-fun
print("This is the first line.", end=" ") # Output: This is the first line. This is the second line.
print("This is the second line.")

The above is the detailed content of Python print() method. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template