字符串拼接

问题:a = 'abc', d='def',g='ghi',将他们拼接起来,用尽可能多的方法


# method_1

handled_str1 = a + d + g

# method_2

def add(str1,str2):

  return str1 + str2

handled_str2 = reduce(add, [a, d, g])

# method_3

handled_str3 = ''.join([a, d, g])


print  'new_str1 = {new_str1}, new_str2 = {new_str2}, new_str3 = {new_str3}.'.format(new_str1=handled_str1,new_str2=handled_str2,new_str3=handled_str3)

print  '{new_str1} == {new_str2}? result = {result}'.format(new_str1=handled_str1,new_str2=handled_str2,result=(handled_str1==handled_str2))

print  '{new_str1} == {new_str2}? result = {result}'.format(new_str1=handled_str1,new_str2=handled_str2,result=(handled_str1==handled_str2))

原文地址:https://www.cnblogs.com/Wolfanature/p/5755709.html