Python Forum
print either int or float - How?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
print either int or float - How?
#2
There are several approaches:
e.g. you can test the variable for it's "type".
a = 3.5
b = 5
if type(a) == float:
    print(a)
if type(b) == int:
    print(b)
or you could do
if int(b) == b:
    print(int(b))
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply


Messages In This Thread
print either int or float - How? - by Denial - Sep-07-2020, 02:51 PM
RE: print either int or float - How? - by DPaul - Sep-07-2020, 04:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python calculate float plus float is incorrect? sirocawa 6 406 Apr-16-2024, 01:45 PM
Last Post: DeaD_EyE
  Comaparing Float Values of Dictionary Against A Float Value & Pick Matching Key firebird 2 3,434 Jul-25-2019, 11:32 PM
Last Post: scidam
  Unable to print the exact Float values when I convert LIST to Sequence of Tuples? preethamalluri 1 2,485 Jul-12-2018, 09:03 AM
Last Post: buran
  Outputting a float value in a print() statement RedSkeleton007 2 3,558 Jan-11-2018, 09:23 AM
Last Post: buran

Forum Jump:

User Panel Messages

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