0% found this document useful (0 votes)
24 views3 pages

Python String Interpolation Examples

Uploaded by

godwinasuquo96
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views3 pages

Python String Interpolation Examples

Uploaded by

godwinasuquo96
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#

number = "67"

quad = float(number) * 4

print ("The quadruple of the number is:",quad)

print()

str_obj="Area"

int_obj=99

print(str_obj, " = ", int_obj)

print()

#a code to accept input from user

display1="Enter the first number"

display2="Enter the second number"

user_value1=int(input(display1))

user_value2=int(input(display2))

Product=user_value1 * user_value2

print("The product of " + str(user_value1) + " and " + str(user_value2) + " is: " + str(float(Product)))

print()

#string interpolation code using concatenation

name="Udoh"

num_bag= 4
rollers=2

print(name + " has " + str(num_bag) + " bags and " + str(rollers) + " rollers.")

print()

#f-strings code for line 45

print(f"{name} has {num_bag} bags and {rollers} rollers.")

print()

#.format() code for line 48

print("{} has {} bags and {} rollers.".format(name, num_bag, rollers))

print()

#string interpolation code using concatenation

newtWeight= 0.2

animal="newt"

print(str(newtWeight) + "kg is the weight of the " + animal + ".")

print()

#f-strings code for line 59

print(f"{newtWeight}kg is the weight of the {animal}.")

print()

#.format() code for line 63

print("{}kg is the weight of the {}.".format(newtWeight, animal))

print()

You might also like