Python Forum
Getting type from input() function in Python 3.0
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting type from input() function in Python 3.0
#3
(Jul-23-2019, 02:48 AM)leodavinci1990 Wrote: How can I get the same functionality of Python 2.0's input() function?
Use int() or float() like this.
data = int(input("Enter any value: "))
print(f'{data} is of type: {type(data)}')
Output:
Enter any value: 5 5 is of type: <class 'int'>
input() in Python 2 should no be used because it had eval(),so i lot posts was made that should never use input() in Python 2.
Python 3 input() just string,but can use int() and float() as showed.
Reply


Messages In This Thread
RE: Getting type from input() function in Python 3.0 - by snippsat - Jul-23-2019, 02:06 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question how to type hint a function in a dataclass? Calab 3 952 Feb-27-2025, 04:40 AM
Last Post: Calab
  Input function oldschool 1 816 Sep-14-2024, 01:02 PM
Last Post: deanhystad
  Is changing processes by using match with type function impossible? cametan 1 784 May-30-2024, 02:16 PM
Last Post: cametan
  difference between forms of input a list to function akbarza 6 2,525 Feb-21-2024, 08:02 PM
Last Post: bterwijn
  determine parameter type in definition function akbarza 1 1,309 Aug-24-2023, 01:46 PM
Last Post: deanhystad
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 2,449 Dec-25-2022, 03:00 PM
Last Post: askfriends
  i want to use type= as a function/method keyword argument Skaperen 9 3,822 Nov-06-2022, 04:28 AM
Last Post: Skaperen
  how to make sure an input is from the wanted type astral_travel 16 5,410 Oct-31-2022, 04:11 PM
Last Post: astral_travel
  Showing an empty chart, then input data via function kgall89 0 1,529 Jun-02-2022, 01:53 AM
Last Post: kgall89
  match type with value in csv parsing function vinci 2 2,228 Jan-21-2022, 12:19 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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