int()

int('string','base') returns integer object
string: input String or number
base: (optional) base of the (input) number.
print(int('45'))  # 45
Using float data type as input
print(int(4.5))  # 4 
print(int(4.78)) # 4
print(int(4.99)) # 4
print(int(4.1))  # 4

With base

Base is 2 here
print(int('0101',2)) # 5
octal base
print(int('107',8)) # 71
Base is 16 here
print(int('ca',16)) # 202
print(int(123,16)) # Error
This will generate output More examples with different base value
my_data='1011' # string input
print("With base 2 : ",int(my_data,2)) # 11
my_data='71'
print("with base 8 :",int(my_data,8)) # 57
my_data='cd' 
print("with base 16 :",int(my_data,16)) # 205
Output
With base 2 :  11
with base 8 : 57
with base 16 : 205

All Built in Functions in Python bin() complex()


plus2net.com



Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer