Python Forum
What a difference print() makes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What a difference print() makes
#1
Hi all,

list1 = ["cat", "dog", "cat", "dog"]
list1.index("cat")
list1.count("dog")
If I enter that in a Jupyter Notebook cell then the output is: 2

list1 = ["cat", "dog", "cat", "dog"]
print(list1.index("cat"))
print(list1.count("dog"))
If I enter that in a Jupyter Notebook cell then the output is 0 with 2 on the very next line.

The .index() and .count() functions are being called in both programs but in the first, the second function return replaces the first function return. How would I explain this observation in pythonic terms?

Thanks!
Reply


Messages In This Thread
What a difference print() makes - by Mark17 - Oct-19-2023, 06:49 PM
RE: What a difference print() makes - by deanhystad - Oct-19-2023, 07:05 PM
RE: What a difference print() makes - by DeaD_EyE - Oct-20-2023, 10:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter + Multiprocessing startmap makes UI Freeze sunny9495 4 1,467 Nov-13-2022, 12:49 PM
Last Post: sunny9495
  Upgrade makes Code Error kucingkembar 6 3,187 Jul-28-2022, 06:44 PM
Last Post: kucingkembar
  help! this 'for' loop makes me crazy lerner50 5 2,962 Jul-09-2019, 03:39 PM
Last Post: perfringo
  Difference between return and print DragonG 9 6,612 Oct-26-2018, 12:06 AM
Last Post: Skaperen
  The number of object makes code slower? fig0 1 2,529 Jan-25-2018, 11:16 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020