Python Forum
Creating a script with a class have specific properties
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating a script with a class have specific properties
#12
(Oct-14-2018, 04:26 AM)CxxJxxYxx Wrote: May I ask why the 'tree' in 'print(tree.report(1))' isn't capitalized? I am confused about this point. Because in previous sentences nothing is defined as 'tree', but only the class 'Tree'

I think this is about my example. Tree is the class. tree is just a variable name, i.e. it could be whatever you want. So tree is an instance of class Tree. It's created on line #18. You are not correct there is nothing defined as tree. From my example:

#example how to instanciate object of class Tree
#ignore numbers if they don't make business sense
   
tree = Tree(block=1, plot=5, species=7, dhb=200)
print(tree.report(1))
Once again - tree is just variable, instance of Tree. You may have many instances of a class in your code.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: Creating a script with a class have specific properties - by buran - Oct-14-2018, 06:47 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I need help writing this code for string properties and methods hannah71605 4 3,199 Mar-22-2021, 12:36 PM
Last Post: menator01
  Creating Email Message Class in Python QuavoJ 1 2,209 Jul-20-2020, 08:30 PM
Last Post: Yoriz
  Sort objects by protected properties. Sigriddenfeta 1 1,935 Mar-17-2020, 04:11 AM
Last Post: Larz60+
  Creating class with getters and setters. amandacstr 3 2,390 Jun-19-2019, 07:10 PM
Last Post: nilamo
  newbie questions about objects properties... slowbullet 2 2,710 Aug-12-2018, 01:12 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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