Getting input in python

Aswin Barath
TechSoftware

--

Getting input from the user is what makes a program more interactive with the user.

Hence, in python we have an input function: input(), to receive input from the user.

Take a look at an example.

Output:

Enter any data:Happy new year!
Happy new year!

input function under the hood

  • When the input() function is encountered by python, the program will pause until the user enters data.
  • Later, any input entered by the user will be converted into a string. Let’s see another example to understand this point.

Output:

Enter any text: Have a great year ahead.
text: Have a great year ahead. , type: <class 'str'>
Enter any number: 2021
number: 2021 , type: <class 'str'>
  • So, in these cases, make sure you convert the input to your preferred data type using its corresponding constructors. Let’s see that example too.

Output:

Enter any number: 2021
number: 2021 , type: <class 'int'>

Who Am I?

I’m Aswin Barath, a Software Engineering Nerd who loves building Web Applications, now sharing my knowledge through Blogging and Community events during the busy time of my freelancing work life.

Here’s the link to all of my craziness categorized by platforms under one place: https://linktr.ee/AswinBarath

For my blog lovers, read more Bite-sized Medium articles from our FB Page on Software Concepts, New & Trending Technologies. We provide a “Friend Link” 🤝 that guarantees anyone free access to our story, even if they’ve read all of their complimentary stories for this month 😍

Join me to learn Python!

Checkout the TechSoftware Feature Page where my mission is to share my knowledge on Python: https://medium.com/techsoftware/python/home

Learn what I know about Python from any of my favourite knowledge sources:

Keep Learning

Now, I guess this is where I say GoodBye👋.
But, hey it’s time for you to start learning with your newfound Knowledge(Power)👨‍💻👩‍💻 .
Good Job that you made it this far 👏👏
Thank you so much for reading my Blog🙂.

Also published at https://aswinbarath.tech

--

--

Aswin Barath
TechSoftware

Freelancer | Community Leader | Blogger | Software Engineer