
hi, I am a beginner, but still you must see this prob. See this code: If i will Put the value of X = 1, it will show Not Valid! , At this moment python should show an error that , how can be the variable X , be int and float at the same time , But still it shows Not Valid! I think it needs to be fixed to make python more intelligent language. if isinstance(x, int) and isinstance(x, float) and x=='1': print("Valid type!") else: print("Not valid!")

Your True clause (when it prints "Valid Type") will only be True when all the following conditions are True : * x is a Integer * x is a float * x is a string equal to '1' Clearly these three things can't be True at the same time, so it executes the 'else' clause. You wont get an error when you use isinstance - it simply returns False if the variable isn't the type you asked about. There is a bug here - but it is in your code. ------ Original Message ------ From: "Yatharth Saini 9A" <yatharthraisaini8h34@gmail.com> To: docs@python.org Sent: Friday, 17 Dec, 21 At 16:14 Subject: [docs] Basic But Very Major Bug hi, I am a beginner, but still you must see this prob. See this code: If i will Put the value of X = 1, it will show Not Valid! , At this moment python should show an error that , how can be the variable X , be int and float at the same time , But still it shows Not Valid! I think it needs to be fixed to make python more intelligent language. if isinstance(x, int) and isinstance(x, float) and x=='1': print("Valid type!") else: print("Not valid!") _______________________________________________ docs mailing list -- docs@python.org To unsubscribe send an email to docs-leave@python.org https://mail.python.org/mailman3/lists/docs.python.org/ <https://mail.python.org/mailman3/lists/docs.python.org/> Member address: anthony.flury@btinternet.com -- <br>Anthony Flury<br>anthony.flury@btinternet.com

Your True clause (when it prints "Valid Type") will only be True when all the following conditions are True : * x is a Integer * x is a float * x is a string equal to '1' Clearly these three things can't be True at the same time, so it executes the 'else' clause. You wont get an error when you use isinstance - it simply returns False if the variable isn't the type you asked about. There is a bug here - but it is in your code. ------ Original Message ------ From: "Yatharth Saini 9A" <yatharthraisaini8h34@gmail.com> To: docs@python.org Sent: Friday, 17 Dec, 21 At 16:14 Subject: [docs] Basic But Very Major Bug hi, I am a beginner, but still you must see this prob. See this code: If i will Put the value of X = 1, it will show Not Valid! , At this moment python should show an error that , how can be the variable X , be int and float at the same time , But still it shows Not Valid! I think it needs to be fixed to make python more intelligent language. if isinstance(x, int) and isinstance(x, float) and x=='1': print("Valid type!") else: print("Not valid!") _______________________________________________ docs mailing list -- docs@python.org To unsubscribe send an email to docs-leave@python.org https://mail.python.org/mailman3/lists/docs.python.org/ <https://mail.python.org/mailman3/lists/docs.python.org/> Member address: anthony.flury@btinternet.com -- <br>Anthony Flury<br>anthony.flury@btinternet.com
participants (2)
-
anthony.flury
-
Yatharth Saini 9A