print() Function:
- The
print()
function is used to display text or variables to the console. - It can take zero or more arguments.
- If multiple arguments are passed, they are separated by a space in the output.
- Example:
- print("Hello, world!")
- The
input()
function is used to accept input from the user. - It displays a prompt (if provided), waits for the user to enter some text, and then returns the text entered as a string.
- Example:
- name = input("Enter your name: ") print("Hello,", name)
input() Function:
Example usage combining both
print()
and input()
:# Asking for user input
name = input("Enter your name: ")
age = input("Enter your age: ")
# Displaying the input received
print("Hello,", name + "! You are", age, "years old.")
In this example:
- The
input()
function prompts the user to enter their name and age. - The entered values are stored in variables
name
andage
. - The
print()
function then displays a greeting message along with the entered name and age.
0 Comments