Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python classes
#10
Ok, this is a bounce of information and difficult to understand.

class Doubleup:
    classvar = 'Hello'
    classvar = 'Goodbye'
     
    def __init__(self):
        self.punctuation = ','
        self.punctuation = '!'
 
    def __init__(self):
        self.punctuation = ';'
        self.punctuation = '?'
 
    def message(self):
        return f'Hello world{self.punctuation}'
 
    def message(self):
        return f'Goodbye world{self.punctuation}'
 
print(Doubleup().message())
From the code above:
- Why isn't the puntuaction defined as argument in the methods?
- What is the function of "f" in return f'Goodbye world{self.punctuation}'?
- What is the curly brackets function in return f'Goodbye world{self.punctuation}'?
- How knows python to refer to the question mark?? This is really difficult to understand for me at the moment...

Maybe the questions are dumb, but I am trying to understand it properly.
Reply


Messages In This Thread
Python classes - by Python_User - Aug-01-2020, 08:13 AM
RE: Python classes - by Gribouillis - Aug-01-2020, 08:50 AM
RE: Python classes - by Python_User - Aug-01-2020, 09:46 AM
RE: Python classes - by snippsat - Aug-01-2020, 10:27 AM
RE: Python classes - by Python_User - Aug-02-2020, 08:04 AM
RE: Python classes - by Gribouillis - Aug-02-2020, 09:32 AM
RE: Python classes - by Python_User - Aug-02-2020, 09:41 AM
RE: Python classes - by snippsat - Aug-02-2020, 10:08 AM
RE: Python classes - by deanhystad - Aug-02-2020, 10:50 AM
RE: Python classes - by Python_User - Aug-02-2020, 03:02 PM
RE: Python classes - by deanhystad - Aug-02-2020, 03:49 PM
RE: Python classes - by Python_User - Aug-02-2020, 05:53 PM
RE: Python classes - by deanhystad - Aug-02-2020, 08:18 PM
RE: Python classes - by Python_User - Aug-03-2020, 06:38 PM
RE: Python classes - by bowlofred - Aug-03-2020, 08:13 PM
RE: Python classes - by Python_User - Aug-04-2020, 06:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Classes rob101 4 627 Feb-05-2024, 06:51 PM
Last Post: rob101
  Understanding Python classes PythonNewbee 3 1,304 Nov-10-2022, 11:07 PM
Last Post: deanhystad
Sad Python classes PythonNewbee 4 1,134 Nov-09-2022, 01:19 PM
Last Post: deanhystad
  Inheritance vs Instantiation for Python classes mr_byte31 7 3,074 Oct-14-2021, 12:58 PM
Last Post: mr_byte31
  Understanding Python super() for classes OmegaRed94 1 1,913 Jun-09-2021, 09:02 AM
Last Post: buran
  Python Classes leodavinci1990 1 2,139 Nov-27-2019, 07:25 AM
Last Post: buran
  Using classes? Can I just use classes to structure code? muteboy 5 5,200 Nov-01-2017, 04:20 PM
Last Post: metulburr
  Python Classes or Functions for large scale application ? Vithulan 5 4,647 Oct-23-2017, 04:48 PM
Last Post: Larz60+
  use of classes in python Lux 2 3,597 Aug-19-2017, 12:29 PM
Last Post: hbknjr
  python classes prsdll6 14 7,608 Aug-17-2017, 07:26 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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