Many times we use string building in many languages and also in python. Here is a tip for a fast string building in Python.
Commonly Used:
string1 = "Example" + " for "+ " String Building" #Commonly used by regular developers
The above method of concatenation is not a best practice most of object oriented language will provide methods for such operations like "join" method in Python.
Best Practice:
string1 = "".join("Example"," for","String Building") #Best practice for faster execution
Using String Building in Python:
string1 = "%s %s %s" % ("Example","for","String Building") # Another Best Practice and very fast
Commonly Used:
string1 = "Example" + " for "+ " String Building" #Commonly used by regular developers
The above method of concatenation is not a best practice most of object oriented language will provide methods for such operations like "join" method in Python.
Best Practice:
string1 = "".join("Example"," for","String Building") #Best practice for faster execution
Using String Building in Python:
string1 = "%s %s %s" % ("Example","for","String Building") # Another Best Practice and very fast
No comments:
Post a Comment