How Do I Interpolate A Variable Into A String?
I have a username, 'jerry' that I want to check if it's in my airtable's Username column: username = 'jerry' rows = at.get_all(formula='FIND('jerry', {Username})=1') # I want to re
Solution 1:
Python 3.6+ offers string interpolation with f-strings, which should be the preferred way of doing this.
So something like this should work:
username = 'jerry'rows = at.get_all(formula=f"FIND('{username}', {{Username}})=1")
Notice the double curly braces to escape them in the string.
Solution 2:
The easiest way in modern Python is to do:
foo = 12
bar = 'hello'print(f"Giving {foo}{bar}'s")
Note the f
in front of the string literal, making it a "f-string" where substitution will take place.
Solution 3:
I believe if you put a .str in before the parentheses the variable is in could do something maybe. ---.str('words')
hope this helps.
Post a Comment for "How Do I Interpolate A Variable Into A String?"