method
A function that belongs to an object or type and is called on a value of it, as in name.upper().
In more detail
The value the method is called on is available inside it, as self in Python or this in Java and JavaScript, so the method can read or change it. Methods give a type its own operations; some return a new value, while others change the object in place.
Examples
func (t Target) Address() string {
return fmt.Sprintf("%s:%d", t.Name, t.Port)
}Go: func (t Target) Address() stringJava: public String greet() { return "Hello, " + name; }public String greet() { return "Hello, " + name; }Node.js APIs are mostly methods on objects such as streams, servers and Buffers.Related terms
- method receiver — The special first parameter of a Go method, written before the method name, that is the value the method is called on.
- pointer receiver — A method receiver declared as a pointer, such as (c *Counter), which lets the method change the original value rather than a copy.
- interface — A named set of member signatures that a type promises to implement, with no state of its own.
- struct — A Go type that groups named fields of different types into one value, such as a Target with a Name and a Port.
- class — A blueprint in code that bundles data and the functions that work on it, from which objects are made.
- static — A keyword marking a field or method as belonging to the class itself, so it can be used without creating an object.
- main method — The method the JVM calls first when it starts a program: public static void main(String[] args).
- function — A named, reusable block of code that takes inputs, called arguments, and can return a result.
- property — A named value belonging to an object; in languages such as C# and Python, it can also be a member that looks like a field but runs code when read or written.
- object — A single thing created from a class or other type, holding its own values and able to run the type's methods.
- object — A piece of data in memory together with the operations, called methods, that belong to it; in Python every value is an object.
- dot notation — Writing object.name to reach a method or attribute that belongs to an object or module, as in s.upper() or math.pi.
- self — The name, by convention, of a method's first parameter, which receives the instance the method was called on.
- string method — A method that belongs to strings, such as upper, lower, count, find, replace, split, strip, startswith or join.
Taught in
- Variables, Typing, and Zero Values — Concurrent Systems Programming with Go
- Structs and Methods — Concurrent Systems Programming with Go
- Interfaces and Why They Are Implicit — Concurrent Systems Programming with Go
- Type Assertions and the Empty Interface — Concurrent Systems Programming with Go
- Calling APIs with net/http Client — Concurrent Systems Programming with Go
- Serving HTTP with net/http Server — Concurrent Systems Programming with Go
- Graceful Shutdown on SIGTERM — Concurrent Systems Programming with Go
- The Virtual Machine, The Kit And The Runtime — Modern Java: Virtual Threads & High-Throughput Services
- The Lifecycle Of A Java Program — Modern Java: Virtual Threads & High-Throughput Services
- A Hundred And Twenty Minutes, Fifty Items — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Promotion, Wrappers And The Math API — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Strings, StringBuilder And Text Blocks — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Dates, Times And Daylight Saving — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Objects, Nested Classes And Garbage Collection — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Classes, Records And Initialisation Order — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Overloading And Varargs — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Scope, var And Immutable Objects — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Inheritance, Overriding And Object's Methods — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sealed Types, Casts And Pattern Matching — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Interfaces: Default, Static And Private Methods — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Enums With Fields, Constructors And Methods — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Object-Oriented Java — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Checked, Unchecked, Catch And Finally — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Try-With-Resources And Suppressed Exceptions — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Arrays: Declare, Sort, Search, Compare — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Generics, Bounds And Wildcards — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Lists, Sets, Maps, Deques And Sequenced Collections — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Exceptions, Arrays And Collections — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Lambdas, Functional Interfaces And Method References — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Reduction, Grouping And Partitioning — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Lambdas And Streams — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Modules: Exports, Opens And Services — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Platform And Virtual Threads, Runnable And Callable — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Thread Safety: Locks And Atomics — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Modules And Concurrency — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Console And File I/O With Streams — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Serialization: What Survives The Trip — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Paths And Files With NIO.2 — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Locales, Resource Bundles And Formatting — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: I/O And Localization — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Final Review And Exam Day — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- V8 Engine & JIT Pipeline: Bytecode & Turbofan — Node.js Internals & Backend Services
- Writable Streams: Drain Events & highWaterMark — Node.js Internals & Backend Services
- A Sample Program, Explained — Hands-on Python: Complete Video Course & Book
- The String Format Method — Hands-on Python: Complete Video Course & Book
- Multiple Parameters — Hands-on Python: Complete Video Course & Book
- Objects, Methods And String Case — Hands-on Python: Complete Video Course & Book
- Reading The graphics.py Documentation — Hands-on Python: Complete Video Course & Book
- Methods, Attributes And self — Hands-on Python: Complete Video Course & Book
- Forty Minutes, Thirty Items: How PCEP Is Run — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Lists: Slices, Methods And Aliases — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Tuples, And The Comma That Makes Them — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Dictionaries: Keys, Values And Items — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Strings: Escapes, Slices And Methods — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Collections Sprint — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Mock, Review And Exam Day — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- The Class That Shared One List — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Exception Classes Of Your Own — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Exceptions Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Comparing, Slicing And Never Changing — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- String Methods The Exam Picks — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Strings Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Classes, Objects And Two Stacks — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Class Variables, Instance Variables And __dict__ — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Methods And The self Parameter — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Introspection: hasattr, __name__, __module__ And __bases__ — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Inheritance, super() And Polymorphism — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Multiple Inheritance, The MRO And Diamonds — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Special Methods: __str__, __eq__ And Friends — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Object-Oriented Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Lambdas, map() And filter() — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Closures: Functions That Remember — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Streams, Handles And Open Modes — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- read, readline, errno And bytearray — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Twelve Traps, Mostly Objects — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Mock, Review And Exam Day — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
References
- The Go spec: method declarations
- Java Tutorials: Defining Methods
- Java Language Specification, chapter 8: Classes
- MDN: Method
- Python glossary: method
- Python tutorial: method objects