The int () function in Python returns an integer object from any number or string. How is the int () function syntax, what parameters does it have and how is it used? Invites you to read the track.
Syntax of int () function in Python
int(value, base) Parameters of int function ()
The int () function has 2 parameters:
Value returned from int ()
The int function returns:
For example, how does the int () function work?
# integerprint("int(123) là:", int(123))
# float# viết bởi TipsMake.comprint("int(123.23) là:", int(123.23))
# stringprint("int('123') là:", int('123'))
Run the program, the result is:
int(123) là: 123int(123.23) là: 123int('123') là: 123
Example 2: Where decimal, octal and hexadecimal?
# nhị phân 0b hoặc 0Bprint("Chuyển đổi giá trị nhị phân 1010 sang int là:", int('1010', 2))print("Chuyển đổi giá trị nhị phân 0b1010 sang int là:", int('0b1010', 2))
# bát phân 0o hoặc 0O
# viết bởi TipsMake.comprint("Chuyển đổi giá trị bát phân 12 sang int là:", int('12', 8))print("Chuyển đổi giá trị bát phân 0o12 sang int là:", int('0o12', 8))
# thập lục phânprint("Chuyển đổi giá trị thập lục phân A sang int là:", int('A', 16))print("Chuyển đổi giá trị thập lục phân 0xA sang int là:", int('0xA', 16))
Run the program, the result is:
Chuyển đổi giá trị nhị phân 1010 sang int là: 10Chuyển đổi giá trị nhị phân 0b1010 sang int là: 10Chuyển đổi giá trị bát phân 12 sang int là: 10Chuyển đổi giá trị bát phân 0o12 sang int là: 10Chuyển đổi giá trị thập lục phân A sang int là: 10Chuyển đổi giá trị thập lục phân 0xA sang int là: 10
Don't forget to explore other important Python functions that TipsMake.com has introduced.
ncG1vNJzZmismaXArq3KnmWcp51ktq%2FAjJ%2Bsp5uknryvecinZKmxpJ28rw%3D%3D