Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Class Question
#1
I'm messing around with Class' and I have a python3 file with the following code:

class playerstats(object):
	def __init__(self, name, baselevel=1, hp, mana, basedmg=0, atkdmg, basedef=0, chardef):
		self.name = name
		self.baselevel = baselevel
		self.hp = hp
		self.mana = mana
		self.basedmg = basedmg
		self.atkdmg = atkdmg
		self.basedef = basedef
		self.chardef = chardef
		return self.name, self.baselevel, self.basedmg, self.basedef
	def selectedclass(self, chosenclass):
		if chosenclass == 'W' or chosenclass == 'w':
			self.hp = 100
			self.mana = 50
		elif chosenclass == 'M' or chosenclass == 'm':
			self.hp = 75
			self.mana = 100
		else:
			print('Error')
		return self.hp, self.mana
		
charcreation = playerstats('Tom', baselevel, self.chosenclass, self.chosenclass, basedmg, 0, basedef, 0)

self.chosenclass = 'w'

print(playerstats.hp)
When I run it, I get this Error:
Error:
File "..\Playground\", line 2 def __init__(self, name, baselevel=1, hp, mana, basedmg=0, atkdmg, basedef=0, chardef): ^ SyntaxError: non-default argument follows default argument
Can someone help me understand why?
Reply


Messages In This Thread
Class Question - by esteel - May-22-2018, 09:18 AM
RE: Class Question - by Rajesh1978 - May-22-2018, 09:25 AM
RE: Class Question - by esteel - May-22-2018, 09:30 AM
RE: Class Question - by Rajesh1978 - May-22-2018, 09:41 AM
RE: Class Question - by volcano63 - May-22-2018, 10:25 AM
RE: Class Question - by esteel - May-22-2018, 10:27 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  newbie question....importing a created class ridgerunnersjw 5 1,018 Oct-01-2020, 07:59 PM
Last Post: ridgerunnersjw
  Class question robdineen 7 1,334 May-30-2020, 05:44 AM
Last Post: Calli
  Question about naming variables in class methods sShadowSerpent 1 897 Mar-25-2020, 04:51 PM
Last Post: ndc85430
  class question jrauden 1 713 Feb-16-2020, 10:14 AM
Last Post: ibreeden
  First Post/ Class Error Question jvan1601 2 2,183 May-01-2017, 04:21 AM
Last Post: jvan1601

Forum Jump:

User Panel Messages

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