Posted By: Anonymous
I’m relatively new to Python and it’s libraries and I was wondering how I might create a string array with a preset size. It’s easy in java but I was wondering how I might do this in python.
So far all I can think of is
strs = ['']*size
And some how when I try to call string methods on it, the debugger gives me an error X operation does not exist in object tuple.
And if it was in java this is what I would want to do.
String ar = new String[size]; Arrays.fill(ar,"");
strs[sum-1] = strs[sum-1].strip('()') AttributeError: 'tuple' object has no attribute 'strip'
Question: How might I do what I can normally do in Java in Python while still keeping the code clean.
In python, you wouldn’t normally do what you are trying to do. But, the below code will do it:
strs = ["" for x in range(size)]