Skip to content

String Formatting

using f-string f

f-string allows us to include expressions in strings.

example of using f-string
name = "Jane"
print(f"Hello {name}") # outputs: Hello Jane

using str.format() method

format() string method helps in formatting strings with placholders

example of using format() string method
# using the above variable "name"
print("Hello {}".format(name))

using percentage formatting %

example of using percentage formatting
#using the above variable "name"
print("Hello %s " % (name))