Python
- key differences between List and Arrays
- Python collections ChainMap
- Array : Find median in an integer array
- Array : Find middle element in an integer array
- Array : Find out the duplicate in an array
- Array : Find print all subsets in an integer array
- Program : Array : Finding missing number between from 1 to n
- Array : Gap and Island problem
- Python collections
- Python Program stock max profit
- Reverse words in Python
- Python array duplicate program
- Coin change problem in python
- Python Write fibonacci series program
- Array : find all the pairs whose sum is equal to a given number
- Find smallest and largest number in array
- Iterate collections
- List comprehensions in Python
- key differences between List and Arrays
- Program: Calculate Pi in Python
- String Formatting in Python
- Python counters
- python tuples
- Python deque
- Python dictionary
- Python Lists
- python namedtuple
String Formatting in Python
In Python, string formatting allows you to create dynamic strings by incorporating variables or values into a text template. There are multiple ways to perform string formatting in Python. Here are a few common methods:
name = "Narender"
age = 30
print("My name is " + name + " and I am " + str(age) + " years old.")
name = "Narender"
age = 25
print("My name is %s and I am %d years old." % (name, age))
name = "Narender"
age = 25
print(f"My name is {name} and I am {age} years old.")
name = "Narender"
age = 25
print("My name is {} and I am {} years old.".format(name, age))
Each method provides a way to incorporate variables or values into a string. You can use different placeholders or format specifiers to control the formatting of variables, such as specifying the number of decimal places for a floating-point number or the width of a field.
It's worth noting that f-strings, introduced in Python 3.6, are generally considered the most convenient and readable way to perform string formatting in Python.