Q:

Python: User input irrespective of the version

I am making a script that takes a string input. However, I want this script to be independent of python 2.7 or python 3+.
For python 2.7 I write
name = raw_input("Enter your name: ")

For python 3+ I write
name = input("Enter your name: ") 

How can I write a single line of code that will be compatible with both the version ?

A:

# Python 2 and 3:
from builtins import input

name = input('What is your name? ')
assert isinstance(name, str)    # native str on Py2 and Py3

