Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am a newbie to python, learning classes and objects.
It is giving me a syntax error like this for code i have written

def__init__(self, n, p, i):

SyntaxError: invalid syntax

What I have tried:

Python
class Person:
    def__init__(self, n, p, i):
    self.name = n
    self.peronality = p
    self.is_sitting = i 
    
    def sitdown(self):
        self.is_sitting = True
        
    def stand_up(self):
        self.is sitting = False
Posted
Updated 21-Apr-20 21:55pm
v2

You are missing a space between def and __init__. Also, you need to fix the indentation of your __init__ block.
 
Share this answer
 
You are missing the space(s) between the keyword def and the function name __init__. It should be:
Python
def __init__(self, n, p, i):

Lots more help at The Python Tutorial — Python 3.7.7 documentation[^].
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900