Dec-12-2021, 08:42 PM
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
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
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags