Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (19.9k points)
recategorized by

I have two lists:

numbers =[2.4, 3.5, 0.5]

operations = ['+', '-']

Note that the values in operations will be changed so I cant just type:

solution = numbers[0] + numbers[1]

I need to insert the value of operations[0] between those numbers.

I've tried:

solution = numbers[0] + operations[0] + numbers[1]

But I can't merge floats and strings values.

1 Answer

0 votes
by (25.1k points)

Instead of using the string version of of the operator from operations list, you can use the operator module. Like this.

print(operators.add(numbers[0], numbers[1]))

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...