LINUX LITE 7.2 FINAL RELEASED - SEE RELEASE ANNOUNCEMENTS SECTION FOR DETAILS


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
int(3) and int('3') is there a difference? (python3.5)
#12
Python is one of my favourite languages.

I think they only mentioned int('2') to demonstrate that int() can convert string data to integer data.

Quote:So its a string that can be added, multiplied, divided etc?

No, a string is more like a list of characters. If you multiply a string by a number, you get a string:

Code:
print("l" + "ol" * 5)

An integer is a numeric value that rounds to the nearest whole number. If you multiply an integer by another numeric value, you get a numeric value.

Code:
print(2.7 * 5)

type is a great command in Python. Here are some things you can try:

Code:
>>> type('5')

>>> type(5.0)

>>> type(int(5))

>>> type(int('5'))

>>> type(str(5))

>>> int('5.0')

>>> float('5.0')

>>> type(float('5.0'))

>>> int(float('5.0'))
Reply


Messages In This Thread
Re: int(3) and int('3') is there a difference? (python3.5) - by freemedia2018 - 04-05-2019, 02:00 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)