Course Content
Data Types in Python
Data Types in Python
Print Your String
What Are Strings in Python?
In Python, a string is a type of data used to store text. This can be anything like a company name, a currency symbol, an invoice note, or a financial report.
To create a string, you just put the text inside quotes. You can use either single quotes '...'
or double quotes "..."
— both work the same.
category = "Office Rent" amount = "12000 UAH" print("Expense Category:", category) print("Amount:", amount)
Double Quotes Help with Apostrophes
If your text includes an apostrophe '
, use double quotes to avoid errors:
note = "Payment for accountant's services (February)" print(note)
Multi-line Strings
Sometimes you need to write text on multiple lines — like a short report or a transaction description. In that case, use triple quotes: '''...'''
or """..."""
.
report = """ March Expense Report: - Office Rent: 12000 UAH - Salaries: 45000 UAH - Internet & Phone: 800 UAH Total Expenses: 57800 UAH """ print(report)
If you try to do this with normal quotes, Python will give an error:
# This will cause an error: description = 'Transaction: Hosting payment for the accounting system.'
Python doesn't allow line breaks inside single-line strings.
Swipe to start coding
Imagine you're tracking the financial state of a company.
-
If your company's financial report this month is bad, assign
"loss"
to the variablefinancial_result
; otherwise, assign "profit". -
If your mood as an accountant is not great, assign
"could be better"
to the variableaccountant_mood
; otherwise, assign "could not be better". -
Does your mood depend on the company's finances? If yes — assign
"yes"
to the variablemood_depends_on_finance
; otherwise — assign"no"
.
Solution
Thanks for your feedback!
Print Your String
What Are Strings in Python?
In Python, a string is a type of data used to store text. This can be anything like a company name, a currency symbol, an invoice note, or a financial report.
To create a string, you just put the text inside quotes. You can use either single quotes '...'
or double quotes "..."
— both work the same.
category = "Office Rent" amount = "12000 UAH" print("Expense Category:", category) print("Amount:", amount)
Double Quotes Help with Apostrophes
If your text includes an apostrophe '
, use double quotes to avoid errors:
note = "Payment for accountant's services (February)" print(note)
Multi-line Strings
Sometimes you need to write text on multiple lines — like a short report or a transaction description. In that case, use triple quotes: '''...'''
or """..."""
.
report = """ March Expense Report: - Office Rent: 12000 UAH - Salaries: 45000 UAH - Internet & Phone: 800 UAH Total Expenses: 57800 UAH """ print(report)
If you try to do this with normal quotes, Python will give an error:
# This will cause an error: description = 'Transaction: Hosting payment for the accounting system.'
Python doesn't allow line breaks inside single-line strings.
Swipe to start coding
Imagine you're tracking the financial state of a company.
-
If your company's financial report this month is bad, assign
"loss"
to the variablefinancial_result
; otherwise, assign "profit". -
If your mood as an accountant is not great, assign
"could be better"
to the variableaccountant_mood
; otherwise, assign "could not be better". -
Does your mood depend on the company's finances? If yes — assign
"yes"
to the variablemood_depends_on_finance
; otherwise — assign"no"
.
Solution
Thanks for your feedback!