35.4k views
2 votes
Which is an example of Python string addition that will run without error?

a. newString = Hello + World!
b. newString = "Hello " + "World!"
c. newString = "Hello ' + "World!'
d. all of the above

1 Answer

3 votes

Final answer:

The correct example of Python string addition without error is newString = "Hello " + "World!".

Step-by-step explanation:

The correct example of Python string addition that will run without error is newString = "Hello " + "World!"



String addition in Python is performed using the + operator. This operator allows you to combine two or more strings together. In the given example, two string literals ('Hello ' and 'World!') are concatenated using the + operator.



The other options (a and c) include syntax errors. In option a, the strings 'Hello' and 'World!' are not enclosed in quotes. In option c, there is a mismatch in the quotes used to define the strings (' and ") which causes a syntax error.