Function vs Method Flashcards

(6 cards)

1
Q

What is the primary difference between a Python function and a method?

A

A method is associated with a specific object or class, while a function is defined independently.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How is a Python function typically defined?

A

Using the def keyword outside of any class structure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How is a Python method typically defined?

A

As a function defined inside a class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the syntax for calling a function?

A

By its name: function_name(args) (e.g., len(my_list)).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the syntax for calling a method?

A

On an object using dot notation: object.method_name(args) (e.g., my_list.append(5)).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the conventional first argument for a method that allows it to operate on the object’s data?

A

self

How well did you know this?
1
Not at all
2
3
4
5
Perfectly