Mastery 28 – User input (text based) in Python (basic)

input(“prompt”) is one of the many Built-in Functions of the Python interpreter.

The prompt is written as an output, the function recieves an input from the user and converts it to a data type, usually a string. For this data to have a meaning in the program, it should be saved inside a variable, so the syntaxys for this would be:

x = input(“prompt”)

on Python 2, this function was raw_input() but now it is just input(). Previously raw_input() returned a string, but now input() can detect if the user entered another type of data such as integer or float.

Mastery 26 – Creation and use of strings in Python

Now we know that input() can creat a string, but what if you have a certain variable and you want it to be a string?

Another handy built-in function is str(variable) which converts the data of the variable into a string.

To concatenate strings you join them with + signs, you can concatenate strings and variables, just be careful, strings need to be inside (” “) and variables do not, but they do need to become a string (if they aren’t already),by doing using the before mentioned function str (variable) to join everything smoothly.

To make a string be seen as an output we use another built-in function, print (“string”) , which is explained more deeply on Mastery 10.

CC BY 4.0 Masteries 26 & 28 by carminaperezguerrero is licensed under a Creative Commons Attribution 4.0 International License.