15,671,201 members
See more:
Python
`x=10'*'12`

I know that if I just remove the quote signs, it'll multiply, but if the * is a string, how do I multiply? This is related to a project of mine, and I'm very new to python.

What I have tried:

I don't even know what to try because it's a python built function
Posted
Updated 5-Apr-22 21:47pm

## Solution 1

You don't, because you're mixing types and assuming that the result will be useful - it won't any more than adding two mobile phone numbers together produces a useful phone number.

What you can do is convert the whole thing to a string and use the Python eval()[^] function to execute it:
Python
```x =  str(2) + '*' + str(4)
print (x)
print (eval(x))```

CPallini 6-Apr-22 2:07am
5.

## Solution 2

Do you mean something like:
Python
```answer = 0
operator = '*'
operand1 = 10
operand2 = 12
if operator == '*':
answer = operand1 * operand2
elif operator == '+':
answer = operand1 + operand2
# etc.
else:
print('invalid operator')```

v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 OriginalGriff 128 Richard MacCutchan 110 Richard Deeming 60 Ralf Meier 25 Rick York 25
 OriginalGriff 1,384 Richard MacCutchan 446 Patrice T 185 Richard Deeming 180 CPallini 135

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900