Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,864 questions

51,786 answers

573 users

What is the StringBuilder() equivalent in Python

4 Answers

0 votes
lst = ['python' for i in range(3)]
 
s = "".join(lst)
 
print(s)
 
  
   
   
   
'''
run:
   
pythonpythonpython
   
'''

 



answered Apr 13, 2021 by avibootz
0 votes
lst = ['python' for i in range(3)]

s = ''
for i in range(len(lst)):
    s += lst[i]

print(s)

 
  
  
  
'''
run:
  
pythonpythonpython
  
'''

 



answered Apr 13, 2021 by avibootz
0 votes
from io import StringIO

class StringBuilder:
     _s = None

     def __init__(self):
         self._s = StringIO()

     def Append(self, str):
         self._s.write(str)

     def __str__(self):
         return self._s.getvalue()

sb = StringBuilder()

sb.Append("Python ")
sb.Append("C++ ")
sb.Append("C")

print(sb)



'''
run:

Python C++ C

'''

 



answered Apr 13, 2021 by avibootz
0 votes
from io import StringIO

lst = ['python' for i in range(3)]

sio = StringIO()  
for i in range(len(lst)):
    sio.write(lst[i])
    
print(sio.getvalue())
  

    
    
    
'''
run:
    
pythonpythonpython
    
'''

 



answered Apr 13, 2021 by avibootz

Related questions

1 answer 173 views
1 answer 113 views
1 answer 148 views
6 answers 414 views
1 answer 216 views
1 answer 180 views
1 answer 96 views
...