Typecasting and Input-Output Functions in Python
A quick overview of Python basics
Presented by: [Your Name]
What is Typecasting?
Typecasting is converting one data type to another.
- Explicit Typecasting - Done manually by the programmer.
- Implicit Typecasting - Done automatically by Python.
Example:
a=5
b = 2.0
c = a + b # c becomes 7.0 (float)
Explicit Typecasting
Common functions: int(), float(), str(), bool()
Example:
x = "10"
y = int(x) # converts string to integer
print(y + 5) # Output: 15
Input Function
input() is used to take user input.
Always returns data as string by default.
Example:
name = input("Enter your name: ")
age = int(input("Enter your age: "))
print(f"Hello {name}, you are {age} years old.")
Output Function
print() is used to display output on screen.
Can print multiple items using , or +.
Supports f-strings, .format(), and % formatting.
Example:
print("Hello", "World")
print("Hello" + " World")
print(f"2 + 3 = {2 + 3}")
Summary
- Typecasting helps in converting data types.
- Input uses input(); always returns a string.
- Output uses print() with multiple formatting options.
Tip: Always convert input to the desired type using int(), float(), etc.