To output a value, use the print function. When you print something, it will appear in the output viewer (aka "the console"). You can print variables, strings, integers, floats, and all data types. We'll get to data types soon.
print("Hello") print(1) print(99.99)
The code above will output:
Hello 1 99.99
Now, there are also other ways to use the print function, including:
# strings can be in single or double quotes print("Message") print('Message') # You can print multiple arguments; you separate arguments with a comma # When the arguments are printed, they are separated by a space by default print('Message', 'with', 'arguments') # would have spaces # You can even use string concatenation ("adding" strings together) # String concatenation puts strings together w/o spaces (be careful about this) print('Message' + 'with' + 'concatenation') # would not have spaces
The output of that:
Message Message Message with arguments Messagewithconcatenation
To input a value, use the
input() function. The
input() function gets user input from the keyboard. When using it, make sure to assign the
input() to a variable that way you store it and can print it.
It is also worth noting that the input prompt goes inside the input function's parentheses. For example, if you wanted to provide the prompt:
"How are you? ", you'd do:
status = input("How are you? ")
print("Hello World") name = input("What is your name? ") print(name) # prints the name that the user entered
If you're confused about variables, click this.