Why wouldn't I just use 'print pi' instead of 'print str(pi)'?


I'm not stuck, per se. Just curious. Title says it all.

#Why would I do this:

print str(pi)

#Instead of simply this:

print pi


I dont know python @scriptcoder87759 , so i may be wrong. But im preety sure when yo do this:

Your printing the Actual String of pi... So essentially that is doing

print "3.14";

But when you just print it like this:

Then your just printing the number :

print 3.14;

In most cases(as of C++ ) , there will be a lot of conversions to std::string, so we can compare to other strings, vectors, lists, and so on... Which one you use depends on your prefrence, and what you are trying to acomplish


No, the parentheses do not have any effect. It's like doing (5) instead of 5

I don't think you'd ever want to compare a number to an array, much less do a string conversion to do it


I never ever said that... I said:

Which means, we may want to convert int to string, for example if we have a binary digit. We may want to store the binary in a vector to! But i never said about comparing an array to a number.. Thats impossible, there are much more numbers,characters, whatever you want to call it in an array than there is in a number


string/list/vector are all essentially arrays

And if you have a number represented as a string, then that's still a number. You wouldn't compare a number to just any array, and if that array represents a number then you can just as well parse the number to a number type.


Bro.. @ionatan What i mean is... Lets take the example:

0001; we may want to store that in a list, or a vector , or an array even... I Never said comparing array to a number.

Thats a simple no. list/vector are essentially arrays, but std::string is not an array lol.


Except if your binary is 00010101011101010101010101 etc.. and even a long long cant store it (as it is 64 bit).So then you store it as a string.. Which has a higher capacity. And also, the 0's in the back will go away, and the int may mess up the binaries.. At least i dont trust it with dealing with binaries


I think it would help in comparison between two strings , such as comparing the length of strings , comparing the i'th character etc....