python: Use the variables defined in the string format as they are

Note that it was convenient. Pass locals () to format ().

ipython


name = 'Taro'
country = 'Japan'
print("I'm {name} from {country}.".format(**locals()))

stdout


I'm Taro from Japan.

reference

Recommended Posts

python: Use the variables defined in the string format as they are
[Python 2/3] Parse the format string
[Python3] Format the character string using the variable name as the key.
Use fabric as is in python (fabric3)
Get the formula in an excel file as a string in Python
Escape curly braces in the format string
The eval () function that calculates a string as an expression in python
Python string format
Python string format
format in python
How to use the C library in Python
Check if the characters are similar in Python
Use python in Docker container as Pycharm interpreter
json.dumping None in python returns the string null
Use the LibreOffice app in Python (3) Add library
Use pydantic when reading environment variables in Python
Use os.getenv to get environment variables in Python
Access the variables defined in the script from the REPL
Use something other than a <br> string for the <br> dict key in Python
Check if the string is a number in python
Use config.ini in Python
Use dates in Python
String manipulation in python
Use Valgrind in Python
[python] Get the list of classes defined in the module
[Python] How to expand variables in a character string
Get the result in dict format with Python psycopg2
Image format in Python
Use the CASA Toolkit in your own Python environment
[Python] format methodical use
Shift the alphabet string by N characters in Python
Specify MinGW as the compiler to use with Python
Let's use the open data of "Mamebus" in Python
Use profiler in Python
How to use the model learned in Lobe in Python
Using the LibreOffice app in Python (1) Where are the macros?
I want to use the R dataset in python
When will the default arguments be bound in python? When variables are bound in closure lazy evaluation.
2015-12-26 python2> datetime> Implementation to take the difference in seconds from two ISO format datetime strings> Use .seconds ()
Make sure all the elements in the list are the same in Python
Find out the apparent width of a string in python
How to use the __call__ method in a Python class
Get the MIME type in Python and determine the file format
Sort and output the elements in the list as elements and multiples in Python.
[Python] Use JSON format data as a dictionary type object
In Django, how to abbreviate the long displayed string as ....
What beginners learned from the basics of variables in python
How to use discrete values as variables in Scipy optimize
Easily format JSON in Python
Use let expression in Python
Use Measurement Protocol in Python
Python indentation and string format
Use callback function in Python
String object methods in Python
Find the difference in Python
Use parameter store in Python
[Python] Use a string sequence
Use HTTP cache in Python
Use MongoDB ODM in Python
Handle environment variables in Python
Use list-keyed dict in Python