如何将字符串拆分为字符串和整数?
How to split a string into a string and an integer?
如何在 python 中将一个字符串拆分为多个字符串。我要拆分的字符串格式为:
Variable 1
我想把它分成:
Variable = Variable
Number = 1
您可以根据您给出的示例中的 space 进行拆分,除非您需要更通用的方法。
# set up your variable
my_var = "variable 1"
# You can split by the space in this instance, if all of your data will look the same
my_split = my_var.split(" ")
# prints variable
print(my_split[0])
# prints 1
print(my_split[1])
如何在 python 中将一个字符串拆分为多个字符串。我要拆分的字符串格式为:
Variable 1
我想把它分成:
Variable = Variable
Number = 1
您可以根据您给出的示例中的 space 进行拆分,除非您需要更通用的方法。
# set up your variable
my_var = "variable 1"
# You can split by the space in this instance, if all of your data will look the same
my_split = my_var.split(" ")
# prints variable
print(my_split[0])
# prints 1
print(my_split[1])