- 3

When would you use string instead of print?

27th Jul 2016, 8:12 PM
Aaron Campbell
2 Answers
+ 2
String is a datatype to store series of characters labelled as some identifier... . print is used to display those "string" by their label along with some messages(if any)
28th Jul 2016, 7:20 AM
Prashant Shahi
Prashant Shahi - avatar
+ 1
print is used to output something to the screen for the user of your application to see. that would be something like printing instructions on what to enter, or printing results of some calculation. you can print strings, numbers or some combination. string is used to store some text in a variable, or to send some text to function. example of the first is when you want to make a program that will reverse a word which is inputted by the user. then you would first store user's input in a variable, do some work on that variable to reverse the string and then probably send that variable to print function to output it to screen. string does not necessarily need to be in a variable, you can use text between quotes (so called string literal) to work on it or send it to a function. example of the second is printing a string to screen - print("Hello world"). here you are sending a string "Hello world" to print function to show it on the screen. so, to sum up, string is a data type used to represent text, while print is a function which can print stuff to screen(including strings) and they are not really interchangeable.
28th Jul 2016, 6:48 AM
RedAnt - avatar