-1

Java has string and string buffer concept.

Is there any concept of string buffer available in python?

3
  • Have you googled your question ? Commented Nov 21, 2014 at 12:38
  • please google well before you hop on the wagon of asking on stackoverflow !! Commented Nov 21, 2014 at 12:55
  • Can you describe this concept? AFAICT Java's StringBuffer does at least three different things, all of which Python's standard library can do but doesn't place in the same type, some for very good reasons. Commented Nov 21, 2014 at 13:01

2 Answers 2

0

Depends on what you want to do. If you want a mutable sequence, the builtin list type is your friend, and going from str to list and back is as simple as:

 mystring = "abcdef"
 mylist = list(mystring)
 mystring = "".join(mylist)

If you want to build a large string using a for loop, the pythonic way is usually to build a list of strings then join them together with the proper separator (linebreak or whatever).

Else you can also use some text template system, or a parser or whatever specialized tool is the most appropriate for the job.

Sign up to request clarification or add additional context in comments.

Comments

0

this link might be useful for concatenation in python

http://pythonadventures.wordpress.com/2010/09/27/stringbuilder/

example from above link:

def g():




 sb = []
    for i in range(30):
       sb.append("abcdefg"[i%7])

   return ''.join(sb)

print g()   

# abcdefgabcdefgabcdefgabcdefgab

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.