nonetype

why does my function is returning data type None??: Python datatype None

做~自己de王妃 提交于 2020-01-07 09:54:40
问题 This is my python code for printing an absolute number. My function is returning type None . I am not getting what I have done wrong. Please help me. def n(num): if num<0: return (num*-1) no = input("Enter a number: ") print "Absolute Value is: " print n(no) 回答1: def n(num): if num<0: return (num*-1) else: return num no = input("Enter a number: ") print "Absolute Value is: " print n(no) writing an else statement will return num >= 0 Thank You :) 回答2: The return is on the condition. Try : def

why does my function is returning data type None??: Python datatype None

天涯浪子 提交于 2020-01-07 09:54:05
问题 This is my python code for printing an absolute number. My function is returning type None . I am not getting what I have done wrong. Please help me. def n(num): if num<0: return (num*-1) no = input("Enter a number: ") print "Absolute Value is: " print n(no) 回答1: def n(num): if num<0: return (num*-1) else: return num no = input("Enter a number: ") print "Absolute Value is: " print n(no) writing an else statement will return num >= 0 Thank You :) 回答2: The return is on the condition. Try : def

My function returns “None”

孤人 提交于 2020-01-07 03:08:08
问题 I am new to Python and I was trying to solve this exercise, but keep getting 'None' output. The question asked for a program in which the input is hours and rate and the output is the gross pay, including overtime if it is more than 40 hours. Anyway, this is the code (I am using Python 3.5.1): def compute_pay (h,r): if h <= 40: pay = h*r return elif h>40: pay = (((h-40)*1.5)*r+(40*r)) return hours = input ("Enter hours:") rate= input ("Enter rate") x = float (hours) y = float (rate) p =

Python `None` passed into type-conversion functions

我们两清 提交于 2020-01-04 15:15:28
问题 What is the rationale for the design decision for None type being passed into type-conversion functions? bool(None) returns False - which makes perfect sense str(None) returns 'None' which is not okay - Returning an empty string would be a better choice as below >>> bool(None) False >>> bool(str(None)) #Returning empty string will make it consistent by returning False True >>> bool('') False And list(None) , dict(None) , tuple(None) , int(None) , float(None) return Type errors - From which if

Python `None` passed into type-conversion functions

烈酒焚心 提交于 2020-01-04 15:15:15
问题 What is the rationale for the design decision for None type being passed into type-conversion functions? bool(None) returns False - which makes perfect sense str(None) returns 'None' which is not okay - Returning an empty string would be a better choice as below >>> bool(None) False >>> bool(str(None)) #Returning empty string will make it consistent by returning False True >>> bool('') False And list(None) , dict(None) , tuple(None) , int(None) , float(None) return Type errors - From which if

How can I append a None value to a list in Python?

烈酒焚心 提交于 2020-01-03 07:36:19
问题 I have a list : A = ['Yes'] I want to have A = ['Yes',None] How can I do this? 回答1: Just use append : A.append(None) >>> print A ['Yes', None] 回答2: Simple: A.append(None) or A += [None] or A.extend([None]) or A[len(A):] = [None] 来源: https://stackoverflow.com/questions/23238489/how-can-i-append-a-none-value-to-a-list-in-python

Python idiom for applying a function only when value is not None

邮差的信 提交于 2019-12-31 02:01:08
问题 A function is receiving a number of values that are all strings but need to be parsed in various ways, e.g. vote_count = int(input_1) score = float(input_2) person = Person(input_3) This is all fine except the inputs can also be None and in this case, instead of parsing the values I would like to end up with None assigned to the left hand side. This can be done with vote_count = int(input_1) if input_1 is not None else None ... but this seems much less readable especially with many repeated

Function Returning a NoneType in Python?

こ雲淡風輕ζ 提交于 2019-12-30 18:33:31
问题 Working on a Python project for CS1, and I have come accross a strange issue that neither I or my roomate can figure out. The general scope of the code is to fill in a grid of 0s with shapes of a certain size using numbers to fill the space, and we have to check along the way to make sure we arent putting shapes in places there there are already shapes. I have two functions here, both do virtually the same thing, but for whatever reason when falsechecker returns the list it returns it as a

Function Returning a NoneType in Python?

荒凉一梦 提交于 2019-12-30 18:32:24
问题 Working on a Python project for CS1, and I have come accross a strange issue that neither I or my roomate can figure out. The general scope of the code is to fill in a grid of 0s with shapes of a certain size using numbers to fill the space, and we have to check along the way to make sure we arent putting shapes in places there there are already shapes. I have two functions here, both do virtually the same thing, but for whatever reason when falsechecker returns the list it returns it as a

'NoneType' object has no attribute 'config'

筅森魡賤 提交于 2019-12-29 06:57:40
问题 What I am trying to do here is add the image to the button I have, then based on click or hover change the image. All the examples I have followed use the .config() method. For the life of me I can't figure out why it doesn't know what the button object is. What is interesting is that if I modify the Button definition line to include the image option, everything is fine. But, with that there it seems I can't modify it using .config() PlayUp = PhotoImage(file=currentdir+'\Up_image.gif')