python字符串拼接

python字符串拼接

# -*- coding: UTF-8 -*-
class HandleStr(object):
    def addStr(self):
        a = "1", "2"
        print(a)
        b = '1' '2'
        print(b)
        c = '1' + '2'
        print(c)
        d = '1' * 10
        print(d)
        e = '111%s222' % 'sdaff'
        print(e)
        f = '111{},222{}'.format('a', 'b')
        print(f)
        g = '111{a},222{b}'.format(a=a, b=b)
        print(g)
        h = '-'.join(['1', '2', '3'])
        print(h)
        i = f'111{a}'
        print(i)


if __name__ == '__main__':
    handleStr = HandleStr()
    handleStr.addStr()

结果

('1', '2')
12
12
1111111111
111sdaff222
111a,222b
111('1', '2'),22212
1-2-3
111('1', '2')

你可能感兴趣的:(python,python)