2) Which of the following is correct way to declare string variable in Python? * a) fruit = 'banana' ) fruit = ("banana"): c) fruit = banana d) fruit = (banana) IN COMPUTER
Answers
Answered by
2
fruit = 'banana' is the correct way to declare string variable in Python.
Answered by
0
Option a) fruit = 'banana' is the correct answer
- Strings are sequences of characters.
- To create a string, the sequence of characters is put inside either single quotes, double quotes, or triple quotes and then assigned to a variable.
- In the question 'banana' is the string and the variable to which it is assigned is 'fruit'.
- We will go through all options and see which of them is correct
- a) fruit = 'banana' => Here the string is put into single quotes and then assigned to a variable. This format is correct.
- b) fruit = ("banana") => Here the string is put into double quotes and then there are brackets put around it after which it is assigned to a variable. This format is not correct, because the string must not have brackets
- c) fruit = banana => Here the string is not put into single quotes but assigned to a variable. This format is not correct, because the string must have either single or double-quotes.
- d) fruit = (banana) => Here the string is not put into single quotes and it has brackets around it but is assigned to a variable. This format is not correct, because the string must not have brackets, and it must have either single or double quotes.
- Hence option a) fruit = 'banana' is correct
#SPJ3
Similar questions
Economy,
1 month ago
Math,
3 months ago
English,
3 months ago
Environmental Sciences,
8 months ago
Math,
8 months ago