Python Input and Output Functions

 ๐Ÿ Python Input and Output Functions

Python provides built-in functions to take input from the user and display output on the screen.


๐Ÿ”น Input Function: input()

The input() function is used to get user input as a string.


๐Ÿง  Syntax:

python

Copy

Edit

variable = input("Enter something: ")

✅ Example:

python

Copy

Edit

name = input("What is your name? ")

print("Hello, " + name + "!")

๐Ÿ“ Note: The input is always stored as a string, even if you enter numbers. To convert it, use functions like int() or float():


python

Copy

Edit

age = int(input("Enter your age: "))

๐Ÿ”น Output Function: print()

The print() function is used to display output on the screen.


๐Ÿง  Syntax:

python

Copy

Edit

print(object1, object2, ..., sep=' ', end='\n')

✅ Examples:

python

Copy

Edit

print("Hello, world!")

You can print multiple items:


python

Copy

Edit

print("Name:", "Alice")

Use sep to change the separator between items:


python

Copy

Edit

print("2025", "04", "12", sep="-")

# Output: 2025-04-12

Use end to change what’s printed at the end:


python

Copy

Edit

print("Hello", end=" ")

print("World")

# Output: Hello World

๐Ÿงช Example Program:

python

Copy

Edit

name = input("Enter your name: ")

age = int(input("Enter your age: "))


print("Hi", name + "!", "You are", age, "years old.")

Let me know if you'd like examples for file input/output (open(), read(), write()) too!

Learn Python Course in Hyderabad

Read More

Python Comments and Their Importance

Where can I find good courses for Python?

Visit Our Quality Thought Training in Hyderabad

Get Directions


Comments

Popular posts from this blog

Understanding Snowflake Editions: Standard, Enterprise, Business Critical

Why Data Science Course?

How To Do Medical Coding Course?