Discussion:
Multiplication
(too old to reply)
Stefan Ram
2024-04-01 08:40:41 UTC
Permalink
Q: How can I multiply two variables in Python? I tried:

a = 2
b = 3
print( ab )

but it did not work.

A: No, this cannot work. To multiply, you need the multiplication
operator. You can import the multiplication operator from "math":

Code example:

from math import *

a = 2
b = 3
print( a * b )
Piergiorgio Sartor
2024-04-01 08:51:05 UTC
Permalink
Post by Stefan Ram
a = 2
b = 3
print( ab )
but it did not work.
A: No, this cannot work. To multiply, you need the multiplication
from math import *
a = 2
b = 3
print( a * b )
I guess the operator "*" can be imported from any module... :-)

bye,
--
piergiorgio
Joel Goldstick
2024-04-01 17:35:26 UTC
Permalink
On Mon, Apr 1, 2024 at 1:26 PM Piergiorgio Sartor via Python-list
Post by Piergiorgio Sartor
Post by Stefan Ram
a = 2
b = 3
print( ab )
but it did not work.
A: No, this cannot work. To multiply, you need the multiplication
from math import *
a = 2
b = 3
print( a * b )
I guess the operator "*" can be imported from any module... :-)
bye,
--
piergiorgio
--
https://mail.python.org/mailman/listinfo/python-list
Post by Stefan Ram
a = 3
b = 5
print(a*b)
15
No import is necessary.
--
Joel Goldstick
D'Arcy Cain
2024-04-01 18:34:36 UTC
Permalink
Post by Joel Goldstick
On Mon, Apr 1, 2024 at 1:26 PM Piergiorgio Sartor via Python-list
^^^^^^^^^^^
Post by Joel Goldstick
Post by Piergiorgio Sartor
Post by Stefan Ram
from math import *
a = 2
b = 3
print( a * b )
I guess the operator "*" can be imported from any module... :-)
No import is necessary.
Of course not. Check the date on the message.
--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:***@Vex.Net VoIP: sip:***@VybeNetworks.com
Avi Gross
2024-04-01 19:02:46 UTC
Permalink
Is this a April 1 post for fools.

Multiplication with an asterisk symbol is built into python.

The same symbol used in other contexts has other contexts has an assortment
of largely unrelated meanings such as meaning everything when used to
import.


On Mon, Apr 1, 2024, 1:27 PM Piergiorgio Sartor via Python-list <
Post by Piergiorgio Sartor
Post by Stefan Ram
a = 2
b = 3
print( ab )
but it did not work.
A: No, this cannot work. To multiply, you need the multiplication
from math import *
a = 2
b = 3
print( a * b )
I guess the operator "*" can be imported from any module... :-)
bye,
--
piergiorgio
--
https://mail.python.org/mailman/listinfo/python-list
dn
2024-04-01 20:02:22 UTC
Permalink
The April Fools joke was on those of us who never received/have yet to
Post by Avi Gross
Is this a April 1 post for fools.
Multiplication with an asterisk symbol is built into python.
The same symbol used in other contexts has other contexts has an assortment
of largely unrelated meanings such as meaning everything when used to
import.
On Mon, Apr 1, 2024, 1:27 PM Piergiorgio Sartor via Python-list <
Post by Piergiorgio Sartor
Post by Stefan Ram
a = 2
b = 3
print( ab )
but it did not work.
A: No, this cannot work. To multiply, you need the multiplication
from math import *
a = 2
b = 3
print( a * b )
I guess the operator "*" can be imported from any module... :-)
bye,
--
piergiorgio
--
https://mail.python.org/mailman/listinfo/python-list
--
Regards,
=dn
Loading...