i know that 6/5 returns 1
and 6/5.0 returns 1.2
but suppose i am defining n=6 and d=5, i want n/d to return 1.2 instead of 1, how do i do it?
abhigyan91 0 Newbie Poster
Recommended Answers
Jump to PostReplying to your second question:
l=['apple','orange','mango','pear','strawberry'] for a in l: if(l=='pear'): l.remove(i)
That ought to work! :P
Why not simpply:
mylist = ['apple','orange','mango','pear','strawberry'] mylist.remove('pear') print(mylist) # ['apple', 'orange', 'mango', 'strawberry']
Jump to Posti know that 6/5 returns 1
and 6/5.0 returns 1.2
but suppose i am defining n=6 and d=5, i want n/d to return 1.2 instead of 1, how do i do it?With Python3 things have changed. Floating point division is now '/' and integer division '//'.
Jump to PostBTW, I am not able to edit my first post in this thread, anyone know why? o.O
You can only edit within 30 minutes after posting.
Jump to PostHe wanted to know how to do it with loops, which is why I posted that code, although I made a type error! :D
This would make more sense for using a loop ...
mylist = ['apple','orange','mango','pear','strawberry'] target = 'pear' newlist = [] for item in mylist: …
All 14 Replies
abhigyan91 0 Newbie Poster
scru 909 Posting Virtuoso Featured Poster

sravan953
snippsat 661 Master Poster

sravan953
bumsfeld 413 Nearly a Posting Virtuoso
bumsfeld 413 Nearly a Posting Virtuoso

sravan953

sravan953
scru 909 Posting Virtuoso Featured Poster
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
abhigyan91 0 Newbie Poster
shadwickman 159 Posting Pro in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.