-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathself_in_python.py
More file actions
43 lines (30 loc) · 1.24 KB
/
self_in_python.py
File metadata and controls
43 lines (30 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# self in python:
"""
1.) Represents somthing that belongs to the class
2.) Can be used to acess the variables and methods inside the same class
3.)Inside the class we have to use self to access the properties and outside the class we have to use object refrence to acess the class properties
4.) self parameter can be renamed
5.) Assigning function parameters to class variables
6.) It is like 'this' keyword of java """
class Car:
wheels = 4 # this the class variable
def initialization_method(self, brand, model, price, milage):
self.brand = brand # These are the instance variables
self.model = model
self.price = price
self.milage = milage
def start_car(self):
print("Car Started");
print(self.brand+"car having model as "+self.model+" has started")
def stop_car(self):
# print("Car Started");
print(self.brand+"car having model as "+self.model+" has stoped")
def example_one(self):
print(self.wheels);
self.start_car();
# Using object refrence we can access the properties of the class outside the class
car = Car();
car.initialization_method("Honda", "Amaze", 900000, 14.5);
car.example_one();
# print(car.wheels);
# car.start_car();