Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Formatting with Ordering | Strings Formatting
String Manipulation in Python
course content

Зміст курсу

String Manipulation in Python

String Manipulation in Python

1. Basic Concepts
2. String Methods
3. Strings Formatting

bookFormatting with Ordering

In the previous chapter, we created a string-pattern, and then inserted variables within it. We did it in order. Another way to create a pattern string - is to predefine the order of inserting.

To do it, we need to specify index of element that should be inserted there. It's a bit obvious, but needs to be clarified: indexation in Python starts with 0, and all the indices within {} blocks must be consecutive (like, {1} {0} {2}, but not {3} {0} {1} as there is no 2). For example,

12
pattern = "{1} manipulation in {0}" print(pattern.format('Python', 'String'))
copy

Note, unless 'Python' was written in the first place it was inserted within the last block (as 'Python' is the first element, and has index 0). The same logic applies to 'string'.

Завдання
test

Swipe to show code editor

Create string holiday with text Independence Day in country is celebrated on the day of month. The order of inserting within .format() function is the next: day, month, and country. According to this, format your string following the order.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 3
toggle bottom row

bookFormatting with Ordering

In the previous chapter, we created a string-pattern, and then inserted variables within it. We did it in order. Another way to create a pattern string - is to predefine the order of inserting.

To do it, we need to specify index of element that should be inserted there. It's a bit obvious, but needs to be clarified: indexation in Python starts with 0, and all the indices within {} blocks must be consecutive (like, {1} {0} {2}, but not {3} {0} {1} as there is no 2). For example,

12
pattern = "{1} manipulation in {0}" print(pattern.format('Python', 'String'))
copy

Note, unless 'Python' was written in the first place it was inserted within the last block (as 'Python' is the first element, and has index 0). The same logic applies to 'string'.

Завдання
test

Swipe to show code editor

Create string holiday with text Independence Day in country is celebrated on the day of month. The order of inserting within .format() function is the next: day, month, and country. According to this, format your string following the order.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 3
toggle bottom row

bookFormatting with Ordering

In the previous chapter, we created a string-pattern, and then inserted variables within it. We did it in order. Another way to create a pattern string - is to predefine the order of inserting.

To do it, we need to specify index of element that should be inserted there. It's a bit obvious, but needs to be clarified: indexation in Python starts with 0, and all the indices within {} blocks must be consecutive (like, {1} {0} {2}, but not {3} {0} {1} as there is no 2). For example,

12
pattern = "{1} manipulation in {0}" print(pattern.format('Python', 'String'))
copy

Note, unless 'Python' was written in the first place it was inserted within the last block (as 'Python' is the first element, and has index 0). The same logic applies to 'string'.

Завдання
test

Swipe to show code editor

Create string holiday with text Independence Day in country is celebrated on the day of month. The order of inserting within .format() function is the next: day, month, and country. According to this, format your string following the order.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

In the previous chapter, we created a string-pattern, and then inserted variables within it. We did it in order. Another way to create a pattern string - is to predefine the order of inserting.

To do it, we need to specify index of element that should be inserted there. It's a bit obvious, but needs to be clarified: indexation in Python starts with 0, and all the indices within {} blocks must be consecutive (like, {1} {0} {2}, but not {3} {0} {1} as there is no 2). For example,

12
pattern = "{1} manipulation in {0}" print(pattern.format('Python', 'String'))
copy

Note, unless 'Python' was written in the first place it was inserted within the last block (as 'Python' is the first element, and has index 0). The same logic applies to 'string'.

Завдання
test

Swipe to show code editor

Create string holiday with text Independence Day in country is celebrated on the day of month. The order of inserting within .format() function is the next: day, month, and country. According to this, format your string following the order.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 3. Розділ 3
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt