0% found this document useful (0 votes)
7 views

Typecasting_and_IO_in_Python

The document provides an overview of typecasting and input-output functions in Python. It explains explicit and implicit typecasting, the use of the input() function for user input, and the print() function for displaying output. Key points include the importance of converting input to the desired type and the various formatting options available in print().

Uploaded by

anshdabholkar25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Typecasting_and_IO_in_Python

The document provides an overview of typecasting and input-output functions in Python. It explains explicit and implicit typecasting, the use of the input() function for user input, and the print() function for displaying output. Key points include the importance of converting input to the desired type and the various formatting options available in print().

Uploaded by

anshdabholkar25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

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.

You might also like