Re: Which part of the loop is it going through in this class frame?

2018-03-09 Thread Cameron Simpson
On 08Mar2018 20:25, C W wrote: Thank you guys, lots of great answers, very helpful. I got it! A follow-up question: How did the value of "object" get passed to "time"? Obviously, they have different names. How did Python make that connection? Code is below for convenience.

Re: Which part of the loop is it going through in this class frame?

2018-03-08 Thread Steven D'Aprano
On Thu, 08 Mar 2018 20:25:42 -0500, C W wrote: > Thank you guys, lots of great answers, very helpful. I got it! > > A follow-up question: > > How did the value of "object" get passed to "time"? Obviously, they have > different names. How did Python make that connection? It didn't. You have

Relationship between ‘object’ and the name of an object (was: Which part of the loop is it going through in this class frame?)

2018-03-08 Thread Ben Finney
C W writes: > A follow-up question: (When you want to switch the discussion to a different subject, please indicate that by changing the Subject field in your message. I am not really clear on what you're asking, so I have guessed and made a subject that I think summarises

Re: Which part of the loop is it going through in this class frame?

2018-03-08 Thread C W
Thank you guys, lots of great answers, very helpful. I got it! A follow-up question: How did the value of "object" get passed to "time"? Obviously, they have different names. How did Python make that connection? Code is below for convenience. class Clock(object): def __init__(self, time):

Re: Which part of the loop is it going through in this class frame?

2018-03-08 Thread Steven D'Aprano
On Wed, 07 Mar 2018 16:57:51 -0500, C W wrote: > Hello, > > I am new to OOP. I'm a bit confused about the following code. > > class Clock(object): > def __init__(self, time): > self.time = time Here you set the instance attribute "self.time". > def print_time(self): >

Re: Which part of the loop is it going through in this class frame?

2018-03-07 Thread dieter
C W writes: > I am new to OOP. I'm a bit confused about the following code. > > class Clock(object): > def __init__(self, time): > self.time = time > def print_time(self): > time = '6:30' > print(self.time) > > clock = Clock('5:30') >

Re: Which part of the loop is it going through in this class frame?

2018-03-07 Thread Frank Millman
"C W" wrote in message news:cae2fw2nudjcmvukavzh01trkqeentkdxdpbawcphhsgx8jv...@mail.gmail.com... Hello, I am new to OOP. I'm a bit confused about the following code. class Clock(object): def __init__(self, time): self.time = time def print_time(self): time = '6:30'

Re: Which part of the loop is it going through in this class frame?

2018-03-07 Thread Dan Sommers
On Wed, 07 Mar 2018 16:57:51 -0500, C W wrote: > class Clock(object): > def __init__(self, time): > self.time = time > def print_time(self): > time = '6:30' > print(self.time) > > clock = Clock('5:30') > clock.print_time() > 5:30 > > I set time to 6:30, but it's

Re: Which part of the loop is it going through in this class frame?

2018-03-07 Thread Dan Sommers
On Wed, 07 Mar 2018 16:57:51 -0500, C W wrote: > Hello, > > I am new to OOP. I'm a bit confused about the following code. > > class Clock(object): > def __init__(self, time): > self.time = time > def print_time(self): > time = '6:30' > print(self.time) > > clock

Re: Which part of the loop is it going through in this class frame?

2018-03-07 Thread Dan Stromberg
On Wed, Mar 7, 2018 at 1:57 PM, C W wrote: > I set time to 6:30, but it's coming out to 5:30. I guess it's because I > passed in 5:30, so, it's replaced? time and self.time are 2 different things. > How does line-by-line execution run inside a frame To quickly come to grips

Re: Which part of the loop is it going through in this class frame?

2018-03-07 Thread Cameron Simpson
On 07Mar2018 16:57, C W wrote: I am new to OOP. I'm a bit confused about the following code. class Clock(object): def __init__(self, time): self.time = time def print_time(self): time = '6:30' print(self.time) clock = Clock('5:30')

Re: Which part of the loop is it going through in this class frame?

2018-03-07 Thread Terry Reedy
On 3/7/2018 4:57 PM, C W wrote: Hello, I am new to OOP. I'm a bit confused about the following code. class Clock(object): def __init__(self, time): self.time = time def print_time(self): time = '6:30' print(self.time) Local name 'time' is bound to '6:30'.

Re: Which part of the loop is it going through in this class frame?

2018-03-07 Thread Ben Finney
C W writes: > I am new to OOP. Welcome, and congratulations on learning Python. > I'm a bit confused about the following code. > > def print_time(self): Begins a function definition. The function will receive one argument (the class instance), and bind the name ‘self’

Re: Which part of the loop is it going through in this class frame?

2018-03-07 Thread jladasky
On Wednesday, March 7, 2018 at 1:58:33 PM UTC-8, C W wrote: > Hello, > > I am new to OOP. There are (at least) two purposes for classes: 1) To group together data and functions in a meaningful way. Functions which are defined inside a class are called methods. 2) To allow the preservation

Which part of the loop is it going through in this class frame?

2018-03-07 Thread Youta TAKAOKA
When we want to set attributes of `self`, we should do it explicitly. Not like `this.` in java or C#, `self.` is needed in python. So, the method > def print_time(self): > time = '6:30' > print(self.time) does 1. set a local variable `time` as '6:30' 2. print `time` which is an

Which part of the loop is it going through in this class frame?

2018-03-07 Thread C W
Hello, I am new to OOP. I'm a bit confused about the following code. class Clock(object): def __init__(self, time): self.time = time def print_time(self): time = '6:30' print(self.time) clock = Clock('5:30') clock.print_time() 5:30 I set time to 6:30, but it's