杰瑞科技汇

Python中如何用print输出orange?

Of course! In Python, you use the print() function to display output.

Python中如何用print输出orange?-图1
(图片来源网络,侵删)

To print the word "orange", you put the word inside the parentheses, enclosed in either single () or double () quotes.

The Basic Code

Here is the simplest way to do it:

print("orange")

Output:

orange

Explanation

  1. print(): This is Python's built-in function that outputs text or other data to the console.
  2. or These are called quotation marks. They tell Python that the text inside is a string** (a sequence of characters). You can use either single or double quotes, as long as they match at the beginning and end of the string.
# Both of these lines work exactly the same
print("orange")
print('orange')

Variations

Here are a few other common ways you might see this used.

Python中如何用print输出orange?-图2
(图片来源网络,侵删)

Printing Multiple Items

You can print multiple things at once by separating them with a comma. Python will automatically add a space between them.

print("I like", "orange")

Output:

I like orange

Printing a Variable

You can store "orange" in a variable and then print the variable.

fruit = "orange"
print(fruit)

Output:

Python中如何用print输出orange?-图3
(图片来源网络,侵删)
orange

Formatted Strings (f-strings)

This is a modern and popular way to embed variables directly inside a string. You put an f before the opening quote and use curly braces around the variable name.

fruit = "orange"
color = "orange"
print(f"The fruit is {fruit} and its color is {color}.")

Output:

The fruit is orange and its color is orange.

For your immediate need, the first and simplest example is all you need:

print("orange")
分享:
扫描分享到社交APP
上一篇
下一篇