Question-12: If you want to print a special character like “’” apostrophe as part of string, how can you achieve that?
- Using Keyword
- Using a variable
- Using escape character
- Using double quote
Answer: C
Exp :
- “\n” python would consider it is a single character.
- “\” is known as escape character.
- It helps in adding new line in a string.
- How to print “\” itself. You have to escape it.
- Similarly for “\’” printing single quote as part of String
Strings
- String always needs a double quote.
- If your string itself require quotes then?
- We already discussed escape character
- Or use apostrophe to create your string.
- If you want only one apostrophe in string, you have to escape it.
print("Learning Python from \"HadoopExam.com\"") print('Learning Python from "HadoopExam.com"') print("Learning Python from 'HadoopExam.com'") print("Wow\' HadoopExam is nice") |