Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
f-strings Conception | 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

bookf-strings Conception

Sometimes we want to output variables with some concomitant text. For example, we want to print the sentence "The capital of country is city". We can use this sentence for any pair country-capital, so we can use it as a template.

Surely, we can use the same approach as before: print each string/variable, separated by a comma. But it's a bit irrational, isn't it? One of the ways of simplifying is using f-strings. They allow you to print strings with variables within single pair of quotes.

Let's consider the syntax. All the text we intend to print should be placed within quotes preceded by symbol f, and all the variables you want to print inside this text should be enclosed with curly brackets. For example,

123
weight = 70 unit = 'kg' print(f"The weight is {weight} {unit}.")
copy

As can seen, there are no redundant commas or quotes. Looks more convenient.

Завдання

Given two variables: name and age. You need to fill the ___ parts to get the message "His name is name. He is age years old." using f-strings. name and age are values of respective variables.

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

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

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

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

bookf-strings Conception

Sometimes we want to output variables with some concomitant text. For example, we want to print the sentence "The capital of country is city". We can use this sentence for any pair country-capital, so we can use it as a template.

Surely, we can use the same approach as before: print each string/variable, separated by a comma. But it's a bit irrational, isn't it? One of the ways of simplifying is using f-strings. They allow you to print strings with variables within single pair of quotes.

Let's consider the syntax. All the text we intend to print should be placed within quotes preceded by symbol f, and all the variables you want to print inside this text should be enclosed with curly brackets. For example,

123
weight = 70 unit = 'kg' print(f"The weight is {weight} {unit}.")
copy

As can seen, there are no redundant commas or quotes. Looks more convenient.

Завдання

Given two variables: name and age. You need to fill the ___ parts to get the message "His name is name. He is age years old." using f-strings. name and age are values of respective variables.

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

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

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

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

bookf-strings Conception

Sometimes we want to output variables with some concomitant text. For example, we want to print the sentence "The capital of country is city". We can use this sentence for any pair country-capital, so we can use it as a template.

Surely, we can use the same approach as before: print each string/variable, separated by a comma. But it's a bit irrational, isn't it? One of the ways of simplifying is using f-strings. They allow you to print strings with variables within single pair of quotes.

Let's consider the syntax. All the text we intend to print should be placed within quotes preceded by symbol f, and all the variables you want to print inside this text should be enclosed with curly brackets. For example,

123
weight = 70 unit = 'kg' print(f"The weight is {weight} {unit}.")
copy

As can seen, there are no redundant commas or quotes. Looks more convenient.

Завдання

Given two variables: name and age. You need to fill the ___ parts to get the message "His name is name. He is age years old." using f-strings. name and age are values of respective variables.

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

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

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

Sometimes we want to output variables with some concomitant text. For example, we want to print the sentence "The capital of country is city". We can use this sentence for any pair country-capital, so we can use it as a template.

Surely, we can use the same approach as before: print each string/variable, separated by a comma. But it's a bit irrational, isn't it? One of the ways of simplifying is using f-strings. They allow you to print strings with variables within single pair of quotes.

Let's consider the syntax. All the text we intend to print should be placed within quotes preceded by symbol f, and all the variables you want to print inside this text should be enclosed with curly brackets. For example,

123
weight = 70 unit = 'kg' print(f"The weight is {weight} {unit}.")
copy

As can seen, there are no redundant commas or quotes. Looks more convenient.

Завдання

Given two variables: name and age. You need to fill the ___ parts to get the message "His name is name. He is age years old." using f-strings. name and age are values of respective variables.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 3. Розділ 1
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
some-alt