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

Advanced Formatting: Sign

Let's now consider the formatting of integer objects. Assume we want to represent our numbers along with plus/minus sign. The minus sign will be printed anyway, but plus sign never prints with an integer.

To make Python print a sign of a number we need to set sign option. There are three of them:

OptionMeaning
: (space after the colon)Use a space before positive number, a minus - before negative
:-Use a minus sign for negative numbers only
:+Use a plus sign for positive numbers, and minus - for negative

For example,

12
print(".{:+}.{: }.".format(3, -7)) print(".{:+}.{: }.".format(-6, 2))
copy

Завдання

Given two variables: min_temp with value -40 and max_temp with value 42. You need to insert correct format options to display - sign for min_temp, and + sign for max_temp, and format string with these variables.

Завдання

Given two variables: min_temp with value -40 and max_temp with value 42. You need to insert correct format options to display - sign for min_temp, and + sign for max_temp, and format string with these variables.

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

Все було зрозуміло?

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

Advanced Formatting: Sign

Let's now consider the formatting of integer objects. Assume we want to represent our numbers along with plus/minus sign. The minus sign will be printed anyway, but plus sign never prints with an integer.

To make Python print a sign of a number we need to set sign option. There are three of them:

OptionMeaning
: (space after the colon)Use a space before positive number, a minus - before negative
:-Use a minus sign for negative numbers only
:+Use a plus sign for positive numbers, and minus - for negative

For example,

12
print(".{:+}.{: }.".format(3, -7)) print(".{:+}.{: }.".format(-6, 2))
copy

Завдання

Given two variables: min_temp with value -40 and max_temp with value 42. You need to insert correct format options to display - sign for min_temp, and + sign for max_temp, and format string with these variables.

Завдання

Given two variables: min_temp with value -40 and max_temp with value 42. You need to insert correct format options to display - sign for min_temp, and + sign for max_temp, and format string with these variables.

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

Все було зрозуміло?

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

Advanced Formatting: Sign

Let's now consider the formatting of integer objects. Assume we want to represent our numbers along with plus/minus sign. The minus sign will be printed anyway, but plus sign never prints with an integer.

To make Python print a sign of a number we need to set sign option. There are three of them:

OptionMeaning
: (space after the colon)Use a space before positive number, a minus - before negative
:-Use a minus sign for negative numbers only
:+Use a plus sign for positive numbers, and minus - for negative

For example,

12
print(".{:+}.{: }.".format(3, -7)) print(".{:+}.{: }.".format(-6, 2))
copy

Завдання

Given two variables: min_temp with value -40 and max_temp with value 42. You need to insert correct format options to display - sign for min_temp, and + sign for max_temp, and format string with these variables.

Завдання

Given two variables: min_temp with value -40 and max_temp with value 42. You need to insert correct format options to display - sign for min_temp, and + sign for max_temp, and format string with these variables.

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

Все було зрозуміло?

Let's now consider the formatting of integer objects. Assume we want to represent our numbers along with plus/minus sign. The minus sign will be printed anyway, but plus sign never prints with an integer.

To make Python print a sign of a number we need to set sign option. There are three of them:

OptionMeaning
: (space after the colon)Use a space before positive number, a minus - before negative
:-Use a minus sign for negative numbers only
:+Use a plus sign for positive numbers, and minus - for negative

For example,

12
print(".{:+}.{: }.".format(3, -7)) print(".{:+}.{: }.".format(-6, 2))
copy

Завдання

Given two variables: min_temp with value -40 and max_temp with value 42. You need to insert correct format options to display - sign for min_temp, and + sign for max_temp, and format string with these variables.

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