我想在字符串中打印变量,该变量是由用户写的

发布于 2025-01-18 18:43:37 字数 164 浏览 2 评论 0原文

name = input('enter the name of the coustomer : ',),
days = int(input('enter the  number of days for :'))

我想在文本输入(名称)的天数后打印名称(由用户输入)

name = input('enter the name of the coustomer : ',),
days = int(input('enter the  number of days for :'))

I want to print name after the text enter the number of days for (name) (type by user )

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我不在是我 2025-01-25 18:43:37
 name = input('enter the name of the coustomer : ')

这里有一个由内置函数 input 给出的 str 类型的 name 变量。

print(name)

您可以使用内置函数print打印它。


我想在文本输入(名称)的天数(由用户输入)后打印名称

您可以将 name 变量与 f-string 一起使用:

days = int(input(f'enter the  number of days for {name}:'))

即使这是最佳实践,f-string 也不是在 Python 中格式化 string 的唯一方法,并且如果您希望它适用于早于 < code>3.6,你可以这样做:

days = int(input('enter the  number of days for {}:'.format(name)))
 name = input('enter the name of the coustomer : ')

Here you have a name variable of type str given by the built-in function input.

print(name)

You can print it with the built-in function print.


I want to print name after the text enter the number of days for (name) (type by user )

You can re-use the name variable with an f-string:

days = int(input(f'enter the  number of days for {name}:'))

Even if it's the best practice, f-string isn't the only way to format a string in Python, and if you want it to work for versions older than 3.6, you can do something like this:

days = int(input('enter the  number of days for {}:'.format(name)))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文