0% found this document useful (0 votes)
7 views1 page

Python Input and Print Functions Guide

Uploaded by

gillesdahan8
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Python Input and Print Functions Guide

Uploaded by

gillesdahan8
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Input Statement:

The input() function is used to obtain input from the user via the keyboard.
Syntax: variable_name = input(prompt_message)
Purpose:
It displays the prompt_message (an optional string) to the user,
instructing them what to enter.
It waits for the user to type something and press Enter.
The entered data is always returned as a string, regardless of whether
numbers or other characters are entered.
The returned string value is then assigned to variable_name.

Ex.
name = input("Enter your name: ")
age_str = input("Enter your age: ")
age = int(age_str) # Type conversion to integer

Output Statement:
The print() function is used to display output to the console or other output
streams.
Syntax: print(value1, value2, ..., sep=' ', end='\n', file=[Link],
flush=False)
Purpose:
It displays one or more values to the output.
sep: An optional string inserted between values (default is a space).
end: An optional string appended after the last value (default is a newline
character).
file: An optional file-like object where the output is written (default is
standard output, [Link]).
flush: A boolean indicating whether to forcefully flush the stream (default
is False).

print("Hello, world!")
name = "Alice"
age = 30
print("Name:", name, "Age:", age, sep=" | ")
print("This is on one line.", end=" ")
print("This continues on the same line.")

You might also like