Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)

I'm generally new to Python and its libraries and I was thinking about how I may make a string array with a preset size. It's simple in java yet I was considering how I may do this in python. 

So far everything I can consider is

str=['']*size

What's more, somehow when I attempt to call string strategies on it, the debugger gives me a blunder X activity doesn't exist in object tuple. 

What's more, in the event that it was in java this is the thing that I would need to do.

String[] ar = new String[size];

Arrays.fill(ar,"");

Kindly help.

This is the Error code:

String[] ar = new String[size];

Arrays.fill(ar,"");

How should I do what I can typically do in Java in Python while as yet keeping the code clean?

1 Answer

0 votes
by (26.4k points)

In python, you wouldn't ordinarily do what you are attempting to do. In any case, the beneath code will do it:

strs=["" for x in range(size)]

Are you interested to learn the concepts of Python? Join the python training course fast!

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...