Programming Terms: String Interpolation

preview_player
Показать описание
In this programming terms video, we will be going over string interpolation. String interpolation is the process of evaluating a string containing one or more placeholders and yielding a result in which the placeholders are replaced with their corresponding values. Let's take a look at this definition in-depth and go over a few examples.

The code from this video can be found at:

✅ Support My Channel Through Patreon:

✅ Become a Channel Member:

✅ One-Time Contribution Through PayPal:

✅ Cryptocurrency Donations:
Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot

✅ Corey's Public Amazon Wishlist

✅ Equipment I Use and Books I Recommend:

▶️ You Can Find Me On:
Рекомендации по теме
Комментарии
Автор

Thank you {name} for all your {adjective} tutorials.format( name=Corey, adjective=outstanding )

joedempseysr.
Автор

Summary:
String Interpolation is a method used to modify the strings. It means when a string value is added in between the string using a placeholder.


It is opposed to the term 'string concatenation', where strings are added up in a repetitive manner in a row.


It is preferred more often because ...
1. being less prone to error such as missing out the spaces as Corey did in the tutorial
2. being more readable as it is shorter in length.
3. easier to modify later on when we need to change the string value that is being embedded within the string.

xcxfgpn
Автор

Its five years ago video but still all python beginners like me felts its new... Thank a lot
Expecting more from you


a='python'
b='corey'
c=f'we can learn {a} easily with {b} '
c
Output:we can learn python easily with corey

Aulin
Автор

That last example of 'greeting' can become an f-string with very little modification, another clear and convenient string interpolation type ; )

This 'programming terms' series has been very useful, especially, for me, the 'closures' explanation.
Many thanks Corey

geoptus
Автор

Python 3.6+ has f-strings
f'I am {age} years old and my name is {name}' is enough.

kamalb
Автор

Thanks for the upload! Very well explained even for newbies

cintiamarques
Автор

Thanks! Looks like string interpolation is a great technique for internationalizing a product

mirtuchy
Автор

In command prompt:

>>> a, b='a-b', 'a-b'
>>> a is b, id(a), id(b)
(False, 13827360, 13826592)
>>> del a
>>> del b
>>> a='a-b';b='a-b'
>>> a is b, id(a), id(b)
(True, 13826592, 13826592)
>>>


In jupyter notebook:

a, b='a-b', 'a-b'
a is b, id(a), id(b)
(True, 83335520, 83335520)
del a; del b
a='a-b';b='a-b'
a is b, id(a), id(b)
(False, 83335576, 83333840)

Both results are opposite.
I don't know why it happens.


So i checked as below:

>>> 'a-b'
'a-b'
>>> id('a-b')
14154912
>>> id('a-b')
14154912
>>> id('a-b')
14154912
>>> a='a-b'
>>> id(a)
14154912
>>> a='a-b'
>>> id(a)
14154848
>>> a='a-b'
>>> id(a)
14154784
>>> a[0], a[1], a[2]
('a', '-', 'b')
>>> id(a[0]), id(a[1]), id(a[2])
(5713184, 5667488, 5754400)
>>> a='a-b'
>>> id(a)
14154880
>>> id(a[0]), id(a[1]), id(a[2])
(5713184, 5667488, 5754400)
>>> id(a)
14154880
>>> 'a-b' is 'a-b'
True
>>> # I checked the id(a) time to time changes when reassigned to 'a-b', but the ids of element
s of a and id('a-b') always remain same. May i know why it is happening so?



>>> id('a-b')
14154912
>>> id('a-b')
14154912
>>> id('a-b'), id('a')
(14154912, 5713184)
>>> id('a-b'), id('a')
(14154912, 5713184)
>>> id('b'), id('a-b'), id('a')
(5754400, 14155072, 5713184)
>>> id('b'), id('a-b'), id('a')
(5754400, 14155072, 5713184)
>>> id('b'), id('a-b'), id('a')
(5754400, 14155072, 5713184)
>>> id('ab'), id('a-b'), id('a')
(14155072, 14154912, 5713184)
>>> id('ab'), id('a-b'), id('a')
(14155072, 14154272, 5713184)
>>> id('ab'), id('a-b'), id('a')
(14155072, 14154912, 5713184)
>>># Why id('a-b') sometimes repeats after one statement and sometimes remain same?



>>> a='a-b'
>>> id(a), id('a-b')
(14154272, 14155040)
>>> id(a), id('a-b')
(14154272, 14155040)
>>> id(a), id('a-b')
(14154272, 14155040)
>>> a='a-b'
>>> id(a), id('a-b')
(14155040, 14155104)
>>> a='a-b'
>>> id(a), id('a-b')
(14155104, 14154912)
>>> a='a-b'
>>> id(a), id('a-b')
(14154912, 14154880)
>>># Why id(a) and id('a-b') are changing?

when i checked in jupyter notebook, the value of id('a-b') always changes
May i know what is the reason?

damodarsahu
Автор

name = john
results = outstanding
print(f'My name is {name} and your tutorials have been

JackShootsFr
Автор

Hi corey, i like your videos. Every second is very informative. I have some doubts. Please clarify me.


t1 =(1, 2, 'a-')
d1 = id(t1)
d2 = id((1, 2, 'a-'))
del t1
t2 =(1, 2, 'a-')
d3 = id(t2)
d4 = id((1, 2, 'a-'))
d1, d2, d3, d4
(85256016, 82259544, 85256016, 85430208) # may i know why d1 and d2 not change but d3 and d4 change?

damodarsahu
Автор

So I should always use String Interpretation over String Concatenation method, when I need to list inside of a function? Because it's better to read and faster to write. Can I use it always or are there some cases were you still need to use String Concatenation?

m.t-thoughts
Автор

is it possible to put the name and age variables into a function and then call them with .format(function(name, age)) somehow?

chilipker
Автор

Which IDE are you using for python? It's really beautiful?

Is it available for windows?

KumailAhmed
Автор

a='ab-c'
b='ab-c'
a is b # False
a[0] is b[0], a[1] is b[1], a[2] is b[2], a[3] is b[3] #(True, True, True, True)

May i know the reason?

damodarsahu
Автор

And after all these years we now have f strings which is even more intuitive than .format
i.e.
greeting = f'' My name is {name} and I am age {age}'

lambball
Автор

Why does some operations result False ?

>>> a='abc';b='xyz'
>>> a is 'abc'
True
>>> b is 'xyz'
True
>>> 'abc'+'xyz' is 'abcxyz'
True
>>> a+b is'abcxyz'
False
>>> c = 'abcxyz'
>>> c is a+b
False
>>> c is 'abcxyz'
True
>>>

damodarsahu