Python Forum
Question about naming variables in class methods
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question about naming variables in class methods
#1
Hi there, in the following code I have a class method called addFormattedCosts. I get that when working with instance variables you use the "self" keyword according to convention. In the below function I didn't use the self before the variables within the method and didn't get an error. The variables used in the method are like "helper" variables and nothing interacts with any actual instance variables which Is why I think I don't get errors. But what affect will occur by not putting the ".self" before these "helper" variables. Should I and why?

def addFormattedCosts(self, costList):
	millionFormat = (float(cost.replace('M', '')) * 1000000 if "M" in cost else 0.0 for cost in costList)
	thousandFormat = (float(cost.replace('K', '')) * 1000 if "K" in cost else 0.0 for cost in costList)
	finalSum = sum(millionFormat) + sum(thousandFormat)
	return int(finalSum)
Reply


Messages In This Thread
Question about naming variables in class methods - by sShadowSerpent - Mar-25-2020, 04:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Very Beginner question on simple variables Harvy 1 189 Apr-12-2024, 12:03 AM
Last Post: deanhystad
  Class test : good way to split methods into several files paul18fr 4 486 Jan-30-2024, 11:46 AM
Last Post: Pedroski55
  question about __repr__ in a class akbarza 4 617 Jan-12-2024, 11:22 AM
Last Post: DeaD_EyE
  Unchangeable variables in a class? Calab 12 1,546 Sep-15-2023, 07:15 PM
Last Post: deanhystad
  Structuring a large class: privite vs public methods 6hearts 3 1,079 May-05-2023, 10:06 AM
Last Post: Gribouillis
  Initiating an attribute in a class __init__: question billykid999 8 1,356 May-02-2023, 09:09 PM
Last Post: billykid999
  naming entities(city abbreviations) tirumalaramakrishna 1 1,250 May-06-2022, 11:22 AM
Last Post: jefsummers
  [Solved] Novice question to OOP: can a method of class A access attributes of class B BigMan 1 1,322 Mar-14-2022, 11:21 PM
Last Post: deanhystad
  access share attributed among several class methods drSlump 0 1,069 Nov-18-2021, 03:02 PM
Last Post: drSlump
  Class variables and Multiprocessing(or concurrent.futures.ProcessPoolExecutor) Tomli 5 3,902 Nov-12-2021, 09:55 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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