What is String Format in Python | Python Tutorial for Beginners

Опубликовано: 25 Июль 2023
на канале: Pycent com
10
1

I have explained old way as well as new way of string formatting:

Old Style String Formatting (% operator):
This style of formatting is similar to the printf style in C programming. It uses the % operator for string interpolation.

Try this Code:

name = "John"
age = 25
print("Good Day, %s. You are %s years old." % (name, age))
Output: Good Day, John. You are 25 years old.

New Way:
String Formatting with the str.format() Method:
The str.format() method is a more flexible way to concatenate and format strings. It uses {} as placeholders for variable substitution.

Try this Code:
name = "John"
age = 25
print("Hi, {}. You are {} years old.".format(name, age))
Output: Hi, John. You are 25 years old.

Notes prepared by:
Pycent.com


На этой странице сайта вы можете посмотреть видео онлайн What is String Format in Python | Python Tutorial for Beginners длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Pycent com 25 Июль 2023, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 10 раз и оно понравилось 1 зрителям. Приятного просмотра!