13

Is there any difference between the two methods var and symbol in the sympy module in python? cause both are working the same way. I googled it and I did not find a detailed explanation for a difference. Are they really the exact same thing or one of them is actually using the other or what?

Safwat Alshazly
  • 331
  • 4
  • 11

1 Answers1

9

There is an answer to that in the FAQ. Basically, var(x) is equal to x = Symbol('x'), but the former doesn't force you to type x twice, while the latter is more explicit. var calls symbols, according to the docs.

Symbol also takes options, as explained in this post. You can pass assumptions (like positive=True), classes (if you want to create a named expression for example) or seq=<True|False> if you want the symbol to be an iterator.

There is also symbols, which can create tuples of symbols quickly, as explained here: a = symbols('a0:%d' % 5), which creates a tuple (a0, a1, a2, a3, a4).

Community
  • 1
  • 1
StefanS
  • 1,740
  • 14
  • 20
  • All what you mentioned is in both `var` and `symbols`, I may then adjust the question, Is there any difference between `symbols` and `var`? – Safwat Alshazly Mar 20 '17 at 08:53
  • 1
    You are right, I didn't look deep enough at first. `var` calls `symbols`, so they are equal. See the updated answer. – StefanS Mar 20 '17 at 09:03