Difference between paste and print (affecting result of function)

前端 未结 2 398
离开以前
离开以前 2020-12-19 14:10

To start off, I\'m not really sure what the difference between paste and print is. But I am using \"print\" to spit out generic statements and \"paste\" to spit out statemen

2条回答
  •  再見小時候
    2020-12-19 14:53

    paste returns the input concatenated together. When a function returns it calls print on whatever was returned if it isn't stored into a variable. Functions return the last top level call if there is no explicit 'return' or 'invisible' statement.

    All of these things add up to what you end up seeing. If paste is the last function called it ends up returning the input concatenated together - which ends up being returned by the function - which ends up being printed since you don't save it into a variable. If you explicitly want something printed it is best to use print or message or cat - they each serve slightly different purposes.

提交回复
热议问题