Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

String Formatting With the .format() Method

Give Feedback

The .format() method is a newer formatting method that should be preferrerd over %-style formatting. In this lesson, you’ll learn when you should use it, how to produce powerful format strings without complicating simpler use cases, and how to format an int variable as a hexadecimal string:

>>>
>>> 'Hey, {name}, there is a 0x{errno:x} error'.format(name=name, errno=errno)
'Hey Bob, there is a 0xbadc0ffee error!'

Comments & Discussion

nmsandy on Aug. 28, 2019

with all tutorial in the python 3

Become a Member to join the conversation.