Escape characters are special sequences that are used inside strings to represent characters or formatting that would otherwise be difficult to write directly.
Escape sequences usually begin with a backslash \.
Common Escape Characters
Escape Character
Purpose
\n
New line
\t
Tab space
\"
Double quotation mark
\'
Single quotation mark
\\
Backslash
Since input() returns a string, you often need to convert the entered value into another data type before performing calculations.
Python provides functions such as:
int() — converts a value to an integer
float() — converts a value to a floating-point number
str() — converts a value to a string
Converting Input to Integer
Use int() when the user needs to enter a whole number, which is essential for ensuring that calculations and data processing functions correctly. This function will cast input data into the Integer type, allowing it to be used in arithmetic operations and logic comparisons effectively.
Adding Two Numbers
num1 = int(input("Enter first number: ")) num2 = int(input("Enter second number: "))
total = num1 + num2
print("Total:", total)
Let's combine input, type conversion, and formatted output in one program to process and display student details interactively.
Input
Output
name = input("Enter your name: ")
age = int(input("Enter your age: "))
course = input("Enter your course: ")
print("\nStudent Information")
print("-------------------")
print(f"Name: {name}")
print(f"Age: {age}")
print(f"Course: {course}")
Enter your name: Amit
Enter your age: 20
Enter your course: Python
Student Information
-------------------
Name: Amit
Age: 20
Course: Python

