Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
positional argument: 'self'
#5
A link on self
The self parameter is a reference to the current instance of the class, and is used to access variables that belongs to the class.

Another example

#! /usr/bin/env python3

import random as rnd

word_list = ['a', 'random', 'list', 'of', 'words']

class Word:
    def __init__(self):
        self.my_list = None

    def get_word(self):
        word = rnd.choice(self.my_list)
        return word

word = Word() # Initiate class instant
word.my_list = word_list # Assign word list to instance variable
print(word.get_word()) # Print results of get word
print(word.get_word()) # Print another result
Output:
words list
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
positional argument: 'self' - by mcmxl22 - Dec-12-2021, 07:50 PM
RE: positional argument: 'self' - by menator01 - Dec-12-2021, 08:08 PM
RE: positional argument: 'self' - by mcmxl22 - Dec-12-2021, 08:16 PM
RE: positional argument: 'self' - by Yoriz - Dec-12-2021, 08:33 PM
RE: positional argument: 'self' - by menator01 - Dec-12-2021, 08:42 PM
RE: positional argument: 'self' - by snippsat - Dec-12-2021, 08:54 PM
RE: positional argument: 'self' - by mcmxl22 - Dec-12-2021, 09:10 PM
RE: positional argument: 'self' - by menator01 - Dec-12-2021, 09:26 PM
RE: positional argument: 'self' - by deanhystad - Dec-13-2021, 10:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: Diagram.render() takes 1 positional argument but 2 were given sachin1361 0 272 Apr-23-2024, 06:39 AM
Last Post: sachin1361
  Error: _vhstack_dispatcher() takes 1 positional argument but 9 were given alexfrol86 3 5,959 May-09-2022, 12:49 PM
Last Post: deanhystad
  What is positional argument self? Frankduc 22 6,016 Mar-06-2022, 01:18 AM
Last Post: Frankduc
  TypeError: run_oracle_job() missing 1 required positional argument: 'connection_strin python_student 1 2,016 Aug-06-2021, 08:05 PM
Last Post: SheeppOSU
  TypeError: sum() missing 1 required positional argument: 'num2' Insen 3 5,576 Jan-06-2021, 04:25 PM
Last Post: Insen
  TypeError: forward() missing 1 required positional argument: 'x' sveto4ka 4 12,419 Jun-17-2020, 07:25 PM
Last Post: sveto4ka
  missing 1 required positional argument: 'self' yasser 7 11,703 Jun-07-2020, 06:48 AM
Last Post: ndc85430
  TypeError: _linspace_dispatcher() missing 1 required positional argument: 'stop' Ae_Lovecraft 3 8,683 May-28-2020, 03:33 PM
Last Post: Larz60+
  SyntaxError: positional argument follows keyword argument syd_jat 3 5,914 Mar-03-2020, 08:34 AM
Last Post: buran
  Type error: dump() missing 1 required positional argument: fp jaycuff13 2 22,183 Jul-13-2019, 10:21 AM
Last Post: jaycuff13

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020