Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Python Coding: Why are some implementations are Functions and some are Methods

$
0
0

For example, when using the "print" Function it works like this:print (string)However, when using the "lower" Method it works like this:string.lower()

Why isn't lower a normal function that works like this:lower (string)

Is there a reason to implement it as a method?(From my recent reading, a method is really just a function inside of a class.)

Does this have something to do with python strings being immutable so the string has to be "recreated" using a method instead of a function?

I tried lower(string) and it says "NameError: name 'lower' is not defined"which makes sense since it's a method.


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>