Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中为字符串赋值_Python_Python 3.x - Fatal编程技术网

如何在python中为字符串赋值

如何在python中为字符串赋值,python,python-3.x,Python,Python 3.x,假设我有一个变量: 数字=100 我想在字符串中使用此变量,但当我这样做时: “数字” 我得到“号码” 我想要100分 我试图直接分配: “数字”=“100” 但它说我不能给字符串赋值 我有办法解决这个问题吗? 谢谢大家! number=str(100) 仅此而已。您不需要更改最初初始化变量号的方式,即作为而不是一个 例如,您可以使用以下命令在新字符串中使用变量: 输出: This is the value of the number variable: 100 <class 'str'&

假设我有一个变量: 数字=100 我想在字符串中使用此变量,但当我这样做时: “数字” 我得到“号码” 我想要100分 我试图直接分配: “数字”=“100” 但它说我不能给字符串赋值 我有办法解决这个问题吗? 谢谢大家!

number=str(100)


仅此而已。

您不需要更改最初初始化变量号的方式,即作为而不是一个

例如,您可以使用以下命令在新字符串中使用变量:

输出:

This is the value of the number variable: 100
<class 'str'>
这是数字变量的值:100

您想解决什么问题?所写的问题似乎表明您希望更改Python语言。
'number'='100'
,为什么您希望数字是字符串?它对您有什么好处?一种语言有一套编写代码的规则,称为语法,不能更改,看起来你的问题是你想做什么是正确的。你的意思是你想把int转换成string?使用string格式化
This is the value of the number variable: 100
<class 'str'>