Thanks for your replies,I think I understand it much better now. I Also I wanted to know what the 'None' does in the second program.
Thanks in Advance Minhaj On Wed, Jun 1, 2016 at 1:59 AM, <tutor-requ...@python.org> wrote: > Send Tutor mailing list submissions to > tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or body 'help' to > tutor-requ...@python.org > > You can reach the person managing the list at > tutor-ow...@python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Tutor digest..." > > Today's Topics: > > 1. Help with 'if' statement and the concept of None (marat murad) > 2. Python OLS help (Vadim Katsemba) > 3. Re: Help with 'if' statement and the concept of None (Alan Gauld) > 4. Re: Python OLS help (Alan Gauld) > 5. Re: Help with 'if' statement and the concept of None > (Steven D'Aprano) > 6. Re: Help with 'if' statement and the concept of None (Ben Finney) > > > ---------- Forwarded message ---------- > From: marat murad <min7...@googlemail.com> > To: tutor@python.org > Cc: > Date: Tue, 31 May 2016 16:16:21 +0100 > Subject: [Tutor] Help with 'if' statement and the concept of None > Hi > I'm learning how to code with python an I have purchased the book 'Python > Programming for the absolute beginner,third edition' by Michael Dawson. > There is one concept that is confusing me in chapter 3 page 71 there is a > program whose code I have pasted below. The author introduced a new way of > coding the Boolean NOT operator with the 'if' statement I have highlighted > the relevant area,apparently this if statement actually means if money != > 0,which I understood,but the program below this one which introduces the > idea of slicing also has a if statement similar to the first one,except the > second one accepts 0 value but the first one doesn't. > > print("Welcome to the Chateau D'food") > print("It seems we are quit full today.\n") > > money = int(input("How many dollars do you slip the Maitr D'? ")) > > *if money:* > print("Ah I think I can make something work") > else: > print("Please sit ,it may be a while") > > > input("\nPress enter to exit") > > > The slicing program > > word = "existential" > > print("Enter the beginning and ending index for the word existential") > print("press he enter key at 'Start' to exit") > > start= None > while start != "": > start=input("\nStart: ") > > * if start:* > start=int(start) > > finish=int(input("Finish: ")) > > print ("word[",start, ":",finish, "]is " , end="") > print(word[start:finish]) > > input("\nPress enter to exit") > > I hope i made sense. > > Thankyou > > > > ---------- Forwarded message ---------- > From: Vadim Katsemba <vkatz...@gmail.com> > To: tutor@python.org > Cc: > Date: Tue, 31 May 2016 11:30:29 -0400 > Subject: [Tutor] Python OLS help > Hello there, I am having trouble running the Ordinary Least Squares (OLS) > regression on Spyder. I typed in lm = > smf.ols(formula='LATITUDE~DIAMETER',data=dataf).fit(), and I ended up > getting this error: ValueError: For numerical factors, num_columns must be > an int. How am I supposed to run the OLS, is there another module I need to > use? Any help would be appreciated. > > > > ---------- Forwarded message ---------- > From: Alan Gauld <alan.ga...@yahoo.co.uk> > To: tutor@python.org > Cc: > Date: Tue, 31 May 2016 23:06:47 +0100 > Subject: Re: [Tutor] Help with 'if' statement and the concept of None > On 31/05/16 16:16, marat murad via Tutor wrote: > > > program whose code I have pasted below. The author introduced a new way > of > > coding the Boolean NOT operator with the 'if' statement I have > highlighted > > the relevant area,apparently this if statement actually means if money != > > 0,which I understood, > > Boolean values are either true or false. > Other values are given boolean equivalent values by Python. > eg. For strings an empty string is False, anything else is True. > For numbers 0 is False anything else is True. > > So in your example: > > > *if money:* > > print("Ah I think I can make something work") > > else: > > print("Please sit ,it may be a while") > > > > The first 'if' test is saying > > 'if money is equivalent to True' (anything other than zero) > > In effect that's the same as you said (it's like testing for != 0) > but the important difference is that it is relying > on the boolean *equivalence* of an integer value. > The same is true in your second example: > > > idea of slicing also has a if statement similar to the first one,except > the > > second one accepts 0 value but the first one doesn't. > > > > > start=input("\nStart: ") > > > > * if start:* > > start=int(start) > > Again this is really saying if start is True and for a string > (which is what input() returns), as I said above, True means > not empty. So the string '0' is not empty and therefore True. > It's not the value of the character that matters it's the fact > that there is a character there at all. > > All objects in Python have these boolean equivalent values, > for example an empty list, tuple,set or dictionary is also > considered False. As is the special value None. > > > I hope i made sense. > > Yes, although your subject also mentions the concept of None? > Did you have another question about that? > > HTH > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos > > > > > > ---------- Forwarded message ---------- > From: Alan Gauld <alan.ga...@yahoo.co.uk> > To: tutor@python.org > Cc: > Date: Tue, 31 May 2016 23:10:49 +0100 > Subject: Re: [Tutor] Python OLS help > On 31/05/16 16:30, Vadim Katsemba wrote: > > Hello there, I am having trouble running the Ordinary Least Squares (OLS) > > regression on Spyder. > > I had no idea what Spyder was but a Google search says its an IDE > somewhat akin to matlab or IPython... It also has a discussion group: > > http://groups.google.com/group/spyderlib > > You may find someone on this list who knows it but you will likely > get a better response on the spyder forum. This list is really > for core python language questions and although we try to be > helpful on other matters a dedicated forum is usually better. > > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos > > > > > > ---------- Forwarded message ---------- > From: "Steven D'Aprano" <st...@pearwood.info> > To: tutor@python.org > Cc: > Date: Wed, 1 Jun 2016 10:12:08 +1000 > Subject: Re: [Tutor] Help with 'if' statement and the concept of None > On Tue, May 31, 2016 at 04:16:21PM +0100, marat murad via Tutor wrote: > > > money = int(input("How many dollars do you slip the Maitr D'? ")) > > *if money:* > > print("Ah I think I can make something work") > > else: > > print("Please sit ,it may be a while") > > All values in Python can be used where a true or false boolean value is > expected, such as in an "if" or a "while" statement. We call this a > "boolean context", meaning something which expects a true or false flag. > > So we have True and False (with the initial capital letter) as special > constants, but we also can treat every other value as if they were true > or false (without the initial capital). Sometimes we call them "truthy" > and "falsey", or "true-like" and "false-like" values. > > For Python built-ins, we have: > > Falsey (false-like) values: > > - zero: 0, 0.0, 0j, Fraction(0), etc. > - empty strings: "", b"" > - empty containers: [], (), {}, set() etc. > (empty list, empty tuple, empty dict, empty set) > - sequences with len() == 0 > - None > - False > > Truthy (true-like) values: > > - non-zero numbers: 1, 2.0, 3j, Fraction(4, 5), etc. > - non-empty strings: "Hello world!", b"\x0" > (yes, even the null-byte is non-empty, since it has length 1) > - non-empty containers > - sequences with len() != 0 > - classes, object() > - True > > We say that "false values represent nothing", like zero, empty strings, > None, and empty containers; while "true values represent something", > that is, anything which is not nothing. > > > So any time you have a value, say, x, we can test to see if x is a > truthy or falsey value: > > > values = [1, 5, 0, -2.0, 3.7, None, object(), (1, 2), [], True] > for x in values: > if x: > print(x, "is a truthy value") > else: > print(x, "is a falsey value") > > > > > -- > Steve > > > > ---------- Forwarded message ---------- > From: Ben Finney <ben+pyt...@benfinney.id.au> > To: tutor@python.org > Cc: > Date: Wed, 01 Jun 2016 10:58:58 +1000 > Subject: Re: [Tutor] Help with 'if' statement and the concept of None > marat murad via Tutor <tutor@python.org> writes: > > > The author introduced a new way of coding the Boolean NOT operator > > with the 'if' statement I have highlighted the relevant > > area,apparently this if statement actually means if money != 0,which I > > understood > > Not quite. The statement actually means “if ‘money’ evaluates as true”. > > Any Python value can be interrogated with the question “Are you true or > false?”, and that is what the ‘if’ statement does. > > This is different from asking ”Is this the True constant or the False > constant?” because for most values the answer is ”Neither”. > > In Python the question “Is this value true, or false?” is usually > implemented as ”Is this value something, or nothing?”. If the value is > conceptually nothing, it evaluates as false when interrogated in a > boolean context. > > See the Python documentation for a comprehensive list of false values > <URL:https://docs.python.org/3/library/stdtypes.html#truth-value-testing>; > any not-false value is true by default. > > If you learn the conceptual “if it's not something, it's false”, then > you will have a fairly good intuition for how ‘if somevalue’ works. > > -- > \ “None can love freedom heartily, but good men; the rest love | > `\ not freedom, but license.” —John Milton | > _o__) | > Ben Finney > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > https://mail.python.org/mailman/listinfo/tutor > > _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor