It’s similar in many ways to the string modulo operator, but. format() method was introduced in version 2.6. If you’ve encountered strange-looking string format code and want to know more, or you need to work with older versions of Python, then it’s a good idea to learn about the other techniques as well. If you’re getting started with Python and you’re looking for a single way to format your strings, then stick with Python 3’s f-Strings. Older techniques are kept around to ensure backward compatibility, and some even have specific use cases. The different string formatting techniques have developed historically over the years that Python has existed and grown. There should be one– and preferably only one –obvious way to do it. You might notice that there are a lot of different ways to format strings in Python, which breaks with one of Python’s very own mantras: You won’t cover either of these techniques in this tutorial, but you’ll want to read up on the string modulo operator if you have to work with code written in Python 2. A related technique, the string modulo operator, provides more or less the same functionality. Note: There’s a standard module called string containing a class called Template, which also provides some string formatting through interpolation.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |