Skip to main content
Practice

What to Watch Out for When Creating String Data?

When defining strings in Python, it is not allowed to start with a double quote (") and end with a single quote ('). You must use the same type of quote at the beginning and the end.

  • Correct Usage: "Hello" or 'Hello'

  • Incorrect Usage: "Hello' or 'Hello"


However, if you want to include quotes within a string, you can alternate between using double quotes and single quotes.

Including Quotes Within a String
# Example using double quotes
response = "My name is 'CodeBuddy'"

# Example using single quotes
response = 'My name is "CodeBuddy"'

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.