๐น 1. Output in Python (print())
The print() function is used to display output on the screen.
Example 1: Simple Output
print("Hello Python")
Output
Hello Python
๐ Explanation
- Text inside quotes is called a string
print()shows it on the screen
Example 2: Printing Multiple Values
name = "Sameer"
age = 25
print(name, age)
Output
Sameer 25
๐ Explanation
- Python automatically adds a space between values
Example 3: Output with Text
name = "Ayesha"
city = "Hyderabad"
print("Name:", name)
print("City:", city)
Output
Name: Ayesha
City: Hyderabad
๐น 2. Input in Python (input())
The input() function is used to take input from the user.
โ Important:input() always returns string data
Example 4: Simple Input
name = input("Enter your name: ")
print("Hello", name)
Sample Output
Enter your name: Chandini
Hello Chandini
๐ Explanation
- User types the name
- Value is stored in
name - Printed using
print()
Example 5: Input Without Message
city = input()
print("City:", city)
Sample Output
Bangalore
City: Bangalore
๐น 3. Problem Without Type Casting
age = input("Enter age: ")
print(age + 1)
โ Error Output
TypeError: can only concatenate str (not "int") to str
๐ Explanation
input()returns string- Python cannot add number to string
๐น 4. Type Casting (Type Conversion)
Type casting means converting one data type to another.
Common Type Casting Functions
| Function | Converts To |
|---|---|
int() | Integer |
float() | Decimal |
str() | String |
bool() | Boolean |
๐น 5. Input with Type Casting (MOST IMPORTANT)
Example 6: Converting Age to Integer
age = int(input("Enter age: "))
print("Next year age:", age + 1)
Sample Output
Enter age: 24
Next year age: 25
๐ Explanation
input()โ stringint()converts it to number- Mathematical operation becomes possible
Example 7: Salary Input
salary = float(input("Enter salary: "))
bonus = 5000
total = salary + bonus
print("Total salary:", total)
Sample Output
Enter salary: 25000
Total salary: 30000.0
๐น 6. Multiple Inputs
Example 8: Student Marks
marks1 = int(input("Enter marks 1: "))
marks2 = int(input("Enter marks 2: "))
total = marks1 + marks2
average = total / 2
print("Total:", total)
print("Average:", average)
Sample Output
Enter marks 1: 80
Enter marks 2: 90
Total: 170
Average: 85.0
๐น 7. Type Casting Between Variables
Example 9: Integer to String
age = 22
text = "Age is " + str(age)
print(text)
Output
Age is 22
Example 10: String to Float
price = "99.5"
new_price = float(price)
print(new_price + 10)
Output
109.5
๐น 8. Boolean Type Casting
Example 11
print(bool(1))
print(bool(0))
print(bool(""))
print(bool("Python"))
Output
True
False
False
True
๐ Explanation
0or empty values โ False- Non-zero or non-empty โ True
๐น 9. Real-Life Example: Employee Details
name = input("Enter name: ")
age = int(input("Enter age: "))
salary = float(input("Enter salary: "))
print("Employee Name:", name)
print("Employee Age:", age)
print("Employee Salary:", salary)
Sample Output
Enter name: Gousya
Enter age: 26
Enter salary: 32000
Employee Name: Gousya
Employee Age: 26
Employee Salary: 32000.0
๐น 10. Common Mistakes (IMPORTANT)
โ Forgetting type casting
โ Adding number with string
โ Wrong data type conversion
๐ง Final Summary
โ print() โ output
โ input() โ user input (string)
โ Type casting converts data types
โ Required for calculations
โ Very important for real programs

Leave a Reply