


But what if you want to show them any results that your program calculated? Up next, you’ll learn how you can display output to your users in the console. With input(), you can collect data from your users. However, this is a security risk because it allows users to run arbitrary, potentially malicious code.įor more information on eval() and its potential security risks, check out Python eval(): Evaluate Expressions Dynamically. You can mimic the effect in Python 3 with the expression eval(input()). Python 3 doesn’t provide a single function that does exactly what Python 2’s input() does. In Python 2, input() reads input from the keyboard, parses and evaluates it as a Python expression, and returns the resulting value. raw_input() in Python 2 behaves just like input() in Python 3, as described above.īut Python 2 also has a function called input(). Raw_input() in Python 2 reads input from the keyboard and returns it. Python Version Note: Should you find yourself working with Python 2.x code, you might bump into a slight difference in the input functions between Python versions 2 and 3. Format string data using Python f-strings.Display output to the console with the built-in function print().Take user input from the keyboard with the built-in function input().

Tied it all together to learn about Python’s for loopsīy the end of this tutorial, you’ll know how to:.

