# theres a lot of ways to concatenate in python # here are all examples that i know: world = 'World!' number = '69' a = 'Hello ' + ' ' + world + ' ' + number b = 'Hello {} {}'.format(world, number) c = f'Hello {world} {number}' # most easy / beginner friendly d = 'Hello %s %s', % (world, number) e = 'Hello', world, number # all of these will print "Hello World! 69" print(a) print(b) print(c) print(d) print(e)
Here is what the above code is Doing:
1. a = ‘Hello ‘ + ‘ ‘ + world + ‘ ‘ + number
– this is the most basic way to concatenate strings
– it’s not very readable, and it’s not very efficient
– it’s not very beginner friendly
2. b = ‘Hello {} {}’.format(world, number)
– this is a little bit more readable, and it’s a little bit more efficient
– it’s not very beginner friendly
3. c = f’Hello {world} {number}’
– this is the most readable, and it’s the most efficient
– it’s very beginner friendly
4. d = ‘Hello %s %s’, % (world, number)
– this is a little bit less readable, and it’s a little bit less efficient
– it’s not very beginner friendly
5. e = ‘Hello’, world, number
– this is the least readable, and it’s the least efficient
– it’s not very beginner friendly