• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Python returning false on checking if a string exists in list even when it does

Resolved: Python returning false on checking if a string exists in list even when it does

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I imported a model(named Feature) and set it to a list in Django
upon calling the 5th element print(posts[5]) this displays apple in shell which is the 5th object however on checking it with a if condition it returns false
and it prints no .. why is this happening even tho apple exists in the list

Answer:

'apple' is a string object. posts is not a list but QuerySet object of Feature objects. It will never find object of other type ๐Ÿ™‚
You have to seek Feature objects like that, in example:
it will print yes.
PS If name is going to be unique you can add unique=True to the model.

If you have better answer, please add a comment about this, thank you!

django python
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How to convert Java bytecode to Webassembly using CheerpJ compiler

24/03/2023

Resolved: Is pandas groupby() function always produce a DataFrame with the same order respect to the column we group by?

24/03/2023

Resolved: Kivy widget hierarchy not behaving as expected

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.