Course Content
Data Types in Python
Data Types in Python
Quotation Marks
You might wonder about using quotes within quotes, like in the example below. This situation can cause an error because Python interprets "Let"
as a string, but then it encounters a problem. For Python, the rest of the string looks like strange symbols in the code.
string = 'Let's eat!' print(string)
Understanding errors is valuable, and knowing how to avoid them is equally important. That's why there are multiple solutions for dealing with "quotes within quotes":
1. Put single quotes inside double quotes, or vice versa;
string1 = "Let's eat!" print(string1) #or string2 = 'Let"s eat!' print(string2)
2. Put the string into triple quotes.
As observed, this approach is consistently employed for lengthy texts that cannot be accommodated on a single line for the sake of readability. In this specific example, it is also appropriate because within the triple-quoted """string"""
, we have the flexibility to include a variety of characters, including both single ('
) and double ("
) quotation marks simultaneously.
string = """Let's eat! or Let"s eat!""" print(string)
Task
Please put quotation marks where necessary to make this sentence readable for Python, too. You can choose one of the two methods that were described.
This is an example of the correct output: John said, 'I am learning data types in Python now'
.
Thanks for your feedback!
Quotation Marks
You might wonder about using quotes within quotes, like in the example below. This situation can cause an error because Python interprets "Let"
as a string, but then it encounters a problem. For Python, the rest of the string looks like strange symbols in the code.
string = 'Let's eat!' print(string)
Understanding errors is valuable, and knowing how to avoid them is equally important. That's why there are multiple solutions for dealing with "quotes within quotes":
1. Put single quotes inside double quotes, or vice versa;
string1 = "Let's eat!" print(string1) #or string2 = 'Let"s eat!' print(string2)
2. Put the string into triple quotes.
As observed, this approach is consistently employed for lengthy texts that cannot be accommodated on a single line for the sake of readability. In this specific example, it is also appropriate because within the triple-quoted """string"""
, we have the flexibility to include a variety of characters, including both single ('
) and double ("
) quotation marks simultaneously.
string = """Let's eat! or Let"s eat!""" print(string)
Task
Please put quotation marks where necessary to make this sentence readable for Python, too. You can choose one of the two methods that were described.
This is an example of the correct output: John said, 'I am learning data types in Python now'
.
Thanks for your feedback!
Quotation Marks
You might wonder about using quotes within quotes, like in the example below. This situation can cause an error because Python interprets "Let"
as a string, but then it encounters a problem. For Python, the rest of the string looks like strange symbols in the code.
string = 'Let's eat!' print(string)
Understanding errors is valuable, and knowing how to avoid them is equally important. That's why there are multiple solutions for dealing with "quotes within quotes":
1. Put single quotes inside double quotes, or vice versa;
string1 = "Let's eat!" print(string1) #or string2 = 'Let"s eat!' print(string2)
2. Put the string into triple quotes.
As observed, this approach is consistently employed for lengthy texts that cannot be accommodated on a single line for the sake of readability. In this specific example, it is also appropriate because within the triple-quoted """string"""
, we have the flexibility to include a variety of characters, including both single ('
) and double ("
) quotation marks simultaneously.
string = """Let's eat! or Let"s eat!""" print(string)
Task
Please put quotation marks where necessary to make this sentence readable for Python, too. You can choose one of the two methods that were described.
This is an example of the correct output: John said, 'I am learning data types in Python now'
.
Thanks for your feedback!
You might wonder about using quotes within quotes, like in the example below. This situation can cause an error because Python interprets "Let"
as a string, but then it encounters a problem. For Python, the rest of the string looks like strange symbols in the code.
string = 'Let's eat!' print(string)
Understanding errors is valuable, and knowing how to avoid them is equally important. That's why there are multiple solutions for dealing with "quotes within quotes":
1. Put single quotes inside double quotes, or vice versa;
string1 = "Let's eat!" print(string1) #or string2 = 'Let"s eat!' print(string2)
2. Put the string into triple quotes.
As observed, this approach is consistently employed for lengthy texts that cannot be accommodated on a single line for the sake of readability. In this specific example, it is also appropriate because within the triple-quoted """string"""
, we have the flexibility to include a variety of characters, including both single ('
) and double ("
) quotation marks simultaneously.
string = """Let's eat! or Let"s eat!""" print(string)
Task
Please put quotation marks where necessary to make this sentence readable for Python, too. You can choose one of the two methods that were described.
This is an example of the correct output: John said, 'I am learning data types in Python now'
.