Day 9: String Manipulation and Formatting

Day 9: String Manipulation and Formatting

Unlocking the Power of Strings: Simple Techniques for Manipulation and Formatting

On my ninth day of learning Python, I'm excited to delve into string manipulation and formatting in this blog post. Together, we'll explore this fundamental data type, and the string, and uncover its intricacies. Let's embark on a journey to deepen our understanding of Python's string operations.

There are some string manipulation techniques in Python:

  1. Format string using the center() method: The center() method, found within Python's str class creates a new string centered within a specified width.

     str = "Himanshu"
     width = 50
     new_str = str.center(width)
     # new string is now centered
     print("New str",new_str)
    
  2. f-string method to manipulate string: f-string method is very fast and convenient to implement. we just need to add f it before the string.

     name = "Himanshu"
     print(f"My name is {name}")
    
  3. Formatting String Python using format() Method: This code employs {} as a placeholder and utilizes the .format() method to substitute values into the designated locations.

     print("we all are {}.".format('equal'))
    

Conclusion

In conclusion, on the ninth day of my Python learning journey, we delved into the fascinating world of string manipulation and formatting. Throughout this blog post, we explored fundamental techniques such as using the center() method to create centered strings within a specified width. We also learned about the efficiency and convenience of f-string formatting, which offers a quick and easy way to insert variables into strings. Additionally, we discussed the versatility of the .format() method for substituting values into placeholders within strings.

Thankyou💕