xxxxxxxxxx
x = ‘apples’
y = ‘lemons’
z = “In the basket are %s and %s” % (x,y)
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
my_list = ['a', 'b', 'c', 'd']
my_string = ','.join(my_list)
# Output = 'a,b,c,d'
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!
xxxxxxxxxx
# Хоёр мөрийн агуулгыг нэг мөр болгон нэгтгэхийн тулд Python нь + операторыг өгдөг.
# Мөрүүдийг холбох энэ процессыг холболт гэж нэрлэдэг.
x = 'One fish, '
y = 'two fish.'
z = x + y
print(z)
# Output: One fish, two fish.