Using a Variable Inside the String
MRAB
python at mrabarnett.plus.com
Mon May 6 15:46:10 EDT 2019
On 2019-05-06 19:44, sveemani at gmail.com wrote:
> Hi all,
>
> I am new learner of python programming and I am into my basics.
> I got struck with the code in a sample program and refer the same with IDE and googling which did not help me for more than a day.
>
> What is wrong with my last 2 lines?
> what I am missing?
>
> ##################
> my_name = 'Veera'
> my_age = 40 # Actually 42
> my_height = 155 # Inches
> my_weight = "80" # checking the double quotes
> my_eyes = 'brown'
> my_teeth = 'white'
> my_hair = 'black'
>
> print(f"Let's talk about {my_name}.")
> print(f"He's {my_height} inches tall.")
> print(f"He's {my_weight} weight heavy.")
> print("Actually thats not too Heavy.")
>
> print(f"He's got {my_eyes} eyes and {my_hair} hair.")
> print(f"His teeth are actually {my_teeth} depending on the coffee.")
>
>
> ### this line are where I Struck #####
'my_age' and 'my_height' are numbers, but 'my_weight' is a string
(why?). You can't add a number and a string together.
> total = my_age + my_height + my_weight
> print(f"If I add {my_age}, {my_height}, and {my_weight} I get {total} .")
>
> ##########################
>
More information about the Python-list
mailing list