2

I want to have something like this code from Python

num=3
res=str(num)

but in Maple. I couldn't find any appropriate constructors for this. Are there any?

Ruslan
  • 162
  • 2
  • 13
83demon
  • 47
  • 5

2 Answers2

3
num:=3:

convert(num,string);

               "3"

sprintf("%a",num);

               "3"
acer
  • 6,671
  • 15
  • 15
1

The best way is to use convert as already exists in @acer's answer. Just to name one more possibility here is another way.

num := 3:
res := cat( "", num );

You will get "3" for res of type string. What cat here does is concatenating 3 to the empty string "", and when there exists at least one string in the arguments of cat, the output becomes a string. You can even have something like sqrt(2) instead of 3 in num, in that case res becomes this string; "2^(1/2)". But sometimes it may give you a non-string object, for example if the number in num is of the form RootOf. See the help page to read more.