How to give a space between 'apple' and 'is ' in a code written in python?
Question:
I have coded Apple is the favorite fruit of SP in python .
But in the output , I got :
Appleis the favorite fruit of SP
Plz help me to identify the mistake and tell me how to add a space between Apple and is.
The code picture link is given below .
Answers:
2 easy ways, first your food could be "apple ", or in your string, insert a space before + "is…, so " is….." In either case, you need to add a space.
You can also use "formatted string literals" (a.k.a. "f-strings", available since Python 3.6) to make it easier on yourself:
>>> f"{food} is the favourite fruit of {name}"
apple is the favourite fruit of sp
You can use format printing here,
hey = "Hello word"
print(hey)
name = "sp"
food = "apple"
print(f"{food} is the favourite food of the {name}")
output
Hello word
apple is the favourite food of the sp
I have coded Apple is the favorite fruit of SP in python .
But in the output , I got :
Appleis the favorite fruit of SP
Plz help me to identify the mistake and tell me how to add a space between Apple and is.
The code picture link is given below .
2 easy ways, first your food could be "apple ", or in your string, insert a space before + "is…, so " is….." In either case, you need to add a space.
You can also use "formatted string literals" (a.k.a. "f-strings", available since Python 3.6) to make it easier on yourself:
>>> f"{food} is the favourite fruit of {name}"
apple is the favourite fruit of sp
You can use format printing here,
hey = "Hello word"
print(hey)
name = "sp"
food = "apple"
print(f"{food} is the favourite food of the {name}")
output
Hello word
apple is the favourite food of the sp