new-operator

Hi, New to coding and cant seem to find the solution for this error (Python)

Hi, New to coding and cant seem to find the solution for this error (Python) Question: text = ["this","is","text"] print(f"hello and {text, end=","}") Input In [58] print(f"hello and {text, end=","}") ^ SyntaxError: f-string: expecting ‘}’ I am trying to remove brackets and commas while using an f string …………………… Asked By: Passiv AHS || Source …

Total answers: 1

TypeError: ">” not supported between instances of "str' and int‘

TypeError: ">” not supported between instances of "str' and int‘ Question: I know I’m missing something with this code. Can someone please help me? I’m new to coding and I’ve struggling with this all day. I don’t want to keep emailing my instructor so maybe I can get help from here. I’m trying to get …

Total answers: 1

Why isn't __new__ in Python new-style classes a class method?

Why isn't __new__ in Python new-style classes a class method? Question: The Changelog for Python 2.2 (where new-style classes were introduced) says the following about the __new__ function: __new__ is a static method, not a class method. I initially thought it would have to be a class method, and that’s why I added the classmethod …

Total answers: 1

inheritance from str or int

inheritance from str or int Question: Why I have problem creating a class inheriting from str (or also from int) class C(str): def __init__(self, a, b): str.__init__(self,a) self.b = b C("a", "B") TypeError: str() takes at most 1 argument (2 given) the same happens if I try to use int instead of str, but it …

Total answers: 6

Is there any reason to choose __new__ over __init__ when defining a metaclass?

Is there any reason to choose __new__ over __init__ when defining a metaclass? Question: I’ve always set up metaclasses something like this: class SomeMetaClass(type): def __new__(cls, name, bases, dict): #do stuff here But I just came across a metaclass that was defined like this: class SomeMetaClass(type): def __init__(self, name, bases, dict): #do stuff here Is …

Total answers: 5