如何在python中打印某个单词后显示文本

2024-05-16 04:29:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在用Python打印一个单词后显示全文

例如:打印“你好”这个词→ 文字出现在“我是一个怪胎乞丐,想学习如何编码成为一名人文学者”之后


Tags: 编码单词全文文字怪胎学者人文乞丐
2条回答

可能您想在输入单词HELLO后打印全文:

word = input("Enter a word: ")
if word == "HELLO":
    print ("I'm a freaking beginner and wanted to learn how to code being a humanities' scholar.")
else:
    print("You didn't enter the word HELLO, you entered the word", word)

假设您要打印两条消息,一条接一条,而第二条消息与第一条消息无关

print("HELLO")
print("I'm a freaking begginer and wanted to learn how to code being a humanities scholar.")

如果要使第二条消息与第一条消息相关,可以尝试:

msg = "HELLO"
print(msg)

if (msg=="HELLO"):
    print("I'm a freaking begginer and wanted to learn how to code being a humanities scholar.")

python命令行不会“响应”您打印到其中的内容-除非您定义一个函数并将消息传递给它:

    def response(msg):
        if (msg=="HELLO"):
            print("...")

 >response("HELLO")
 >...

相关问题 更多 >