How input() function works?
- The flow of the program has stopped until the user enters the input.
- The text statement which also knows as prompt is optional to write in input() function. This prompt will display the message on the console.
- The input() function automatically converts the user input into string. We need to explicitly convert the input using the type casting.
- raw_input() - The raw_input function is used in Python’s older version like Python 2.x. It takes the input from the keyboard and return as a string. The Python 2.x doesn’t use much in the industry. Let’s understand the following example.
Example -
# Python program showing
# a use of raw_input()
name = raw_input("Enter your name : ")
print name
Output:
Enter your name: Peter
Peter
How to check Python version?
To check the Python version, open command line (Windows), shell (Mac), or terminal (Linux/Ubuntu) and run python -version . It will display the corresponding Python version.
Check Python version in the running script
We can check the Python version in our running script. Consider the following ways to know Python version in all operating systems.
Commands | Operating System/Environment | Output |
---|---|---|
Python --version or |
Python -v or
Python -vv|Window/Mac/Linux|Python 3.8.1|
|import sys
sys.version
sys.version_info|Python Script|3.8.3 (default, May 13 2020, 15:29:51) [MSC v.1915 64 bit (AMD64)]|
|Import platform
platform.python_version()|Python Script|‘3.8.1’|
Let’s have a look at following image.