xxxxxxxxxx
first_name = 'Albert'
last_name = 'Einstein'
full_name1 = first_name + last_name
print(full_name1)
full_name2 = first_name + ' ' + last_name
print(full_name2)
# Output - AlbertEinstein
# Output - Albert Einstein
xxxxxxxxxx
# 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)
xxxxxxxxxx
x="String"
y="Python"
d="+"
c = "We can concatenation " + y + x + "with" + d + "Operator"
print(c)
xxxxxxxxxx
#How to concatenate in python with f strings
# This is the best way I have seen to concatenate a string with and integer
a = 'aaa'
b = 'bbb'
c = 'ccc'
d = 12
txt = f'{a}{b}{c}{d}'
print(txt)
It will print:
aaabbbccc12
#It works as long as you have python 3.6.0 or up!
# I am jsut glad it works
#if you have a mac computer with vs code on it edit the .json file and change python to python 3 if you have python 3 already installed!