【发布时间】:2020-04-05 20:01:06
【问题描述】:
我对 Python 编码有疑问,我使用的 IDE 是 Pycharm 社区版。
我有这样的代码
i = 0
str_1 = """public class Schedule_Boolean_Monday_""" + str(i) + """ {
public Schedule_Boolean_Monday_""" + str(i) + """_3(Context context){
this.mContext = context;
}
}"""
for i in range(3):
print(str_1)
而电流输出是这样的
public class Schedule_Boolean_Monday_0 {
public Schedule_Boolean_Monday_0_3(Context context){
this.mContext = context;
}
}
public class Schedule_Boolean_Monday_0 {
public Schedule_Boolean_Monday_0_3(Context context){
this.mContext = context;
}
}
public class Schedule_Boolean_Monday_0 {
public Schedule_Boolean_Monday_0_3(Context context){
this.mContext = context;
}
}
public class Schedule_Boolean_Monday_0和public Schedule_Boolean_Monday_0_3(Context context)不变。 String 中的 str(i) 不会递增。我想得到这样的输出
public class Schedule_Boolean_Monday_0 {
public Schedule_Boolean_Monday_0_3(Context context){
this.mContext = context;
}
}
public class Schedule_Boolean_Monday_1 {
public Schedule_Boolean_Monday_1_3(Context context){
this.mContext = context;
}
}
public class Schedule_Boolean_Monday_2 {
public Schedule_Boolean_Monday_2_3(Context context){
this.mContext = context;
}
}
这可以增加字符串内的整数值吗? 我很想听听你的建议。
非常感谢
【问题讨论】:
标签: python python-3.x for-loop increment