-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
Introduction to Python
Python Basics
Python Syntax
Python Comments
Python Variables
Python Data Types
Python Casting
Python I/O
Python Operators
Cotrol Structures
Data Structures
Python Strings
Python Lists
Python Tuples
Python Dictionaries
Python Sets
Python Arrays
Python Bytes and Bytearray
Date and Time
Functions and Module
File Handling
Python OOP
Advanced Concepts
Python Scope
Python Modules
Python JSON
Python RegEx
Python PIP
Python Try...Except
Python String Formatting
Python User Input
Python VirtualEnv
Python Math
Python DSA
Python DSA
Lists and Arrays
Python Stacks
Python Queues
Linked Lists
Python Hash Tables
Python Trees
Python Binary Trees
Binary Search Trees
Python AVL Trees
Python Graphs
Searching Algorithms
Sorting Algorithms
Python provides simple functions to take input from the user and output data to the screen.
📥 Input → Collect data from the user using the input()
function
📤 Output → Display data using the print()
function
print()
The print()
function is used to show messages or variable values on the screen.
Syntax:
print(value1, value2, ..., sep=' ', end='\n')
print("Hello, World!")
print("Name:", "John")
print("Hello", end=" ")
print("World!")
sep
: Separator between values (default is space)
end
: What to print at the end (default is newline \n
)
input()
The input()
function reads a line of text entered by the user.
Syntax:
variable = input("Enter something: ")
The input is always received as a string, even if the user types a number.
You can convert it to int/float using int()
or float()
.
name = input("Enter your name: ")
age = int(input("Enter your age: "))
Since input()
returns a string, you can cast it like this:
num1 = int(input("Enter number 1: "))
num2 = float(input("Enter number 2: "))
Operation | Function | Returns |
---|---|---|
Display output | print() |
None |
Get input | input() |
str |
Q1. Write a Python program to display your name using the print()
function.
Q2. Write a Python program to take the user's name as input and greet them with a message.
Q3. Write a Python program to accept two numbers from the user and display their sum.
Q4. Write a Python program to ask the user to enter their age and display it with a message like “You are 25 years old”.
Q5. Write a Python program to use end=' '
and print two words on the same line.
Q6. Write a Python program to accept a float number from the user and print its type.
Q7. Write a Python program to take input for a subject name and print a sentence using it, like “I love Math”.
Q8. Write a Python program to ask the user to enter 3 words and print them separated by commas using sep=','
.
Q9. Write a Python program to take a string input and convert it to uppercase before printing.
Q10. Write a Python program to get two numbers from the user and display their product.
Introduction to Python
Python Basics
Python Syntax
Python Comments
Python Variables
Python Data Types
Python Casting
Python I/O
Python Operators
Cotrol Structures
Data Structures
Python Strings
Python Lists
Python Tuples
Python Dictionaries
Python Sets
Python Arrays
Python Bytes and Bytearray
Date and Time
Functions and Module
File Handling
Python OOP
Advanced Concepts
Python Scope
Python Modules
Python JSON
Python RegEx
Python PIP
Python Try...Except
Python String Formatting
Python User Input
Python VirtualEnv
Python Math
Python DSA
Python DSA
Lists and Arrays
Python Stacks
Python Queues
Linked Lists
Python Hash Tables
Python Trees
Python Binary Trees
Binary Search Trees
Python AVL Trees
Python Graphs
Searching Algorithms
Sorting Algorithms