Special Formatting For Strings In Python

Inserting values into a string

age = 24
name = "George"
print(f"My name is {name}. I am {age} years old.")Output:
My name is George. I am 24 years old.

Formatting space alongside insertions

for name, age in zip(["Jim", "Sylvester"], [21, 29]:
print(f"{name:{9} is {age}.")
Output:
Jim is 21.
Sylvester is 29.

--

--

--

Data scientist learning at Flat Iron School

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Must have Management tools

Claims Transformation in .NET 6

Oh Snap — I’m a Full Stack Web Developer Now!

Daily Progress — Getting Free Animations from Mixamo into your Unity Game

GitOps and IaC Security

Mutating Kubernetes resources with Gatekeeper

Why business and IT don’t understand each other

asdf, runtime version automatic change

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Datascience George

Datascience George

Data scientist learning at Flat Iron School

More from Medium

Demystifying Python assertEqual()

Python practice: Q1. Guess a number

Pytest with Python.!!!

Python Checkbutton| Tkinter Python main Checkbutton Kaise Create Kare