Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Quotation Marks | Рядки
Типи даних у Python
course content

Зміст курсу

Типи даних у Python

Типи даних у Python

1. Знайомство з числами в Python
2. Істина чи брехня?
3. Рядки
4. Поєднання всіх тем разом

book
Quotation Marks

Strings can be enclosed in either single quotes ('...') or double quotes ("..."). However, if you need to use quotes inside your string, you must be careful to avoid syntax errors.

123
# This will raise a syntax error due to the apostrophe inside single quotes transaction_note = 'Today's payment was delayed' print(transaction_note)
copy

Python interprets the apostrophe ' in "Today's" as the end of the string, which causes confusion in the rest of the line.

Correct Ways to Use Quotes Within Strings

Use double quotes outside if the string contains an apostrophe:

123
# Using double quotes allows us to include an apostrophe safely transaction_note = "Today's payment was delayed" print(transaction_note)
copy

Use single quotes outside if the string contains double quotes:

123
# Using single quotes to include a quote in the text audit_remark = 'The client said: "We will send the invoice tomorrow."' print(audit_remark)
copy

Use triple quotes to include both types of quotation marks

Triple quotes ('''...''' or """...""") are often used for multi-line text, but they are also useful when a string contains both single and double quotes:

123
# Triple quotes allow both single and double quotation marks financial_summary = """Today's report includes the note: "Check the 'Q1' revenue drop." """ print(financial_summary)
copy

Practical Accounting Example

1234567891011
# Correct use of quotes to log an accountant's comment comment = "The accountant's note: 'Double-check the tax deduction before approval.'" print(comment) # Using triple quotes to format a longer, multi-line report comment report_comment = """ Manager's instructions: - Review the 'Accounts Receivable' section. - Confirm with the accountant: "Is the write-off policy still valid?" """ print(report_comment)
copy

This approach ensures your strings are syntactically correct and improves code readability, especially when working with real-world financial data that may include quotations in documentation or remarks.

Завдання

Swipe to start coding

The sentence below contains both single quotes and regular text. To make it a valid string in Python, add the correct quotation marks around the sentence. You can use one of the methods described earlier (double quotes outside, or triple quotes).

Рішення

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

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

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

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

book
Quotation Marks

Strings can be enclosed in either single quotes ('...') or double quotes ("..."). However, if you need to use quotes inside your string, you must be careful to avoid syntax errors.

123
# This will raise a syntax error due to the apostrophe inside single quotes transaction_note = 'Today's payment was delayed' print(transaction_note)
copy

Python interprets the apostrophe ' in "Today's" as the end of the string, which causes confusion in the rest of the line.

Correct Ways to Use Quotes Within Strings

Use double quotes outside if the string contains an apostrophe:

123
# Using double quotes allows us to include an apostrophe safely transaction_note = "Today's payment was delayed" print(transaction_note)
copy

Use single quotes outside if the string contains double quotes:

123
# Using single quotes to include a quote in the text audit_remark = 'The client said: "We will send the invoice tomorrow."' print(audit_remark)
copy

Use triple quotes to include both types of quotation marks

Triple quotes ('''...''' or """...""") are often used for multi-line text, but they are also useful when a string contains both single and double quotes:

123
# Triple quotes allow both single and double quotation marks financial_summary = """Today's report includes the note: "Check the 'Q1' revenue drop." """ print(financial_summary)
copy

Practical Accounting Example

1234567891011
# Correct use of quotes to log an accountant's comment comment = "The accountant's note: 'Double-check the tax deduction before approval.'" print(comment) # Using triple quotes to format a longer, multi-line report comment report_comment = """ Manager's instructions: - Review the 'Accounts Receivable' section. - Confirm with the accountant: "Is the write-off policy still valid?" """ print(report_comment)
copy

This approach ensures your strings are syntactically correct and improves code readability, especially when working with real-world financial data that may include quotations in documentation or remarks.

Завдання

Swipe to start coding

The sentence below contains both single quotes and regular text. To make it a valid string in Python, add the correct quotation marks around the sentence. You can use one of the methods described earlier (double quotes outside, or triple quotes).

Рішення

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

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

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

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