Python: formatted strings (fstrings) and format specification for str, int and float objects

Channel:
Subscribers:
7,760
Published on ● Video Link: https://www.youtube.com/watch?v=pfbTjDRlpfI



Duration: 19:04
115 views
5


Python can use str concatenation, fstrings, the str format method and the % operator to incorporate objects into a str. This video discusses the use of these and format specifiers for the str, int and float data types.

Written Notes:
https://dellwindowsreinstallationguide.com/python-fstrings/

rstring:
r"C:\Windows"

fstring:
f"{}" (the {} is used as a placeholder for an object)
f"{object}"
The colon : is used after the object to specify the formatting options. The abbreviations s, d and f are used to denote a str, int and a float.
f"{str_object:s}"
f"{int_object:d}"
f"{float_object:f}"
For a str the additional parameter n can can be used to specify the number of characters, the str should occupy.
f"{str_object:ns}"
An int also uses n but this can be prepended with 0 to display leading zeroes.
f"{int1:0nd}"
For the case of a float, one of the characters specified by n is the decimal point . n can be prefixed by 0 to display leading zeroes and suffixed by .m to specify the number of places after the decimal point.
f"{float1:0n.mf}"
In many cases only .m will be specified.
f"{float1:.mf}"




Other Videos By Philip Yip


2021-06-25Windows 11 Elevated System Requirements
2021-06-21Hexadecimal Colour Encoding Explanation using a Red, Green, Blue LED
2021-06-20A Clean Install of Zorin Linux 16 Beta (Dell UEFI BIOS with Secure Boot and MOK)
2021-06-18Python Object Orientated Programming (Spyder 5 IDE)
2021-06-13Python Code Blocks and Debugging (Spyder 5 IDE)
2021-06-10Python Procedural Programming (Spyder 5 IDE)
2021-05-26A Clean Install of KDE Neon Dell UEFI BIOS with Secure Boot
2021-05-23Getting Started with Python and the Spyder 5 IDE (Object Orientated Programming OOP)
2021-05-17A Clean Install of DeepIn Linux 20.2.2 Dell UEFI BIOS and Secure Boot
2021-05-16A Clean Install of Linux Mint 20.2 (Dell UEFI BIOS with Secure Boot and MOK)
2021-05-07Python: formatted strings (fstrings) and format specification for str, int and float objects
2021-03-121. Getting Started with Python and the JupyterLab 3 IDE. Object Orientated Programming (OOP)
2021-02-10Windows 10 Insider Preview New Emoji Panel, Clipboard History and Touchscreen Keyboard Feedback
2021-01-15DeepIn 20.1 Touchscreen Test on XPS 13 9365
2021-01-12XPS 13 Wacom Touchscreen Issues on Linux Mint 20.1
2021-01-02Windows 10 Environment Variables
2020-11-28Create Windows 10 (UEFI or Legacy BIOS) Bootable USB on Windows 10 (All Versions 15H1-21H2)
2020-11-18Dell Thunderbolt Dock Ubuntu 20.04 Boot Issue
2020-11-18Updating the Dell UEFI BIOS with the Ubuntu Linux Firmware Update Manager or USB Flash Drive
2020-11-14Updating the Dell UEFI BIOS in Ubuntu 20.04 Using the Linux Vendor Firmware Service (LVFS)
2020-10-11Making a Screen Recording in Windows 10 using the Free VokoscreenNG