简体   繁体   English

如何仅更改代码的特定部分?

[英]How do I change only a certain part of the code?

I do not have a code but may I know how to do something like that:我没有代码,但我可以知道如何做这样的事情:

I want to print " is happy."我要打印“很高兴”。 The outputs should be John is happy.输出应该是约翰很高兴。 Mary is happy.玛丽很高兴。 Tom is happy.汤姆很高兴。

only the part changes here so how can I do so with this {} included?这里只有部分发生了变化,所以我怎么能在包含这个 {} 的情况下这样做?

Is this what you are looking for?这是你想要的? Have some kind of list of oyur names.有一些oyur名字的列表。 Then you can print using a for loop然后你可以使用 for 循环打印

names = ["john", "mary"]
for name in names:
    print("{} is happy".format(name))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何仅显示字典的某些部分? - How do i display only certain part of a dictionary? 如何仅获取 HTML 树的一部分,该部分位于带有特定字符串 BeautifulSoup 的特定标签之上? - How do I get only the part of an HTML tree which is above a certain tag with certain string BeautifulSoup? Python中,如何只注释掉特定部分的代码? - In Python, how do I comment out a specific part of the code only? 如何选择 NumPy 数组的某个部分,然后选择下一部分? - How do I select a certain part of NumPy array and then the next part? 如何使用复杂列表中的数字作为标题/如何仅打印与某个值匹配的列表的一部分 - How do I use a number from a complex list as a heading / How do I print only part of a list that matches a certain value 如何更改此代码的输出以仅输出前 2 张卡片? - How do I change the output of this code to only output the first 2 cards? 我该如何创建一个类,该类从python中的另一个类继承方法,但又仅更改某个方法的某些部分? - How can I make a class that inherits methods from another class in python but also change only some part of a certain method? 如何在 python 文件部分中调用 screenmanager 以仅在选择所有微调器时更改屏幕 - How do I call screenmanager in python file part to change screens only when all spinners are selected 如何获得 JSON 请求但获得其中的某个部分? - How do I get a JSON request but get a certain part of it? 如何删除 Python OpenCV 中图像的某些部分? - How do I remove certain part of an Image in Python OpenCV?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM