Is str() a method or function?


#1

Hi,
Is str() a method or function?

The first Python lesson on "str()" (https://www.codecademy.com/en/courses/python-beginner-sRXwR/1/4?curriculum_id=4f89dab3d788890003000096) calls it a method:

"The Now let's look at str(), which is a little less straightforward. The str() method turns non-strings into strings!"

But the docs at https://docs.python.org/3/library/functions.html list it as a function.

I know that methods are just functions that are called using the attribute notation, and who knows how all this works under the hood.

The code required to solve this problem is:

 str(pi)

What's the most correct way to refer to that code: method or function?

Thanks,

David


#2

@hiersd,

If you use google search
== discussions / opinions ==
python function vs method site:stackoverflow.com


#3

I think It Is a method because in
the last course of the unit, you w
-ill see that it is one of the three
ways to form a string; str(), "", and ,''.


#4

@markliami, @hiersd

Have a look at the documentation.....
https://docs.python.org/2/library/functions.html


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.