Get the App
SLTechnology News&Howtos  ›  Development  › 

How to input read digits by input in python

Shulou Source: shulou.com Published: 2022-06-03 17:38:42 09月19日 Update

This article mainly introduces the python input how to input and read numbers, the article is very detailed, has a certain reference value, interested friends must read it!

1. Starting with Python3, input returns a string that must be explicitly converted to ints, using int.

X = int (input ("Enter a number:")) y = int (input ("Enter a number:"))

2. You can accept any cardinality and use the int function to convert them directly to cardinality.

> data = int (input ("Enter a number:"), 8) Enter a number: 777 > data511 > data = int (input ("Enter a number:"), 16) Enter a number: FFFF > > data65535 > data = int (input ("Enter a number:"), 2) Enter a number: 10101010101 > > data1365

The second parameter tells what the cardinality of the input number is, and then it understands and converts it internally. If the data entered is incorrect, a ValueError will be thrown.

> data = int (input ("Enter a number:"), 2) Enter a number: 1234Traceback (most recent call last): File ", line 1, in ValueError: invalid literal for int () with base 2: '1234'

For values that can have decimal parts, the type will be float instead of int:

X = float (input ("Enter a number:")) these are all the contents of the article "how to input and read numbers in input in python". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Input number cardinality content article value interest function parameter character string boy partner decimal data more knowledge type industry information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Huawei Linux Apple Shulou Information