```a = (1)
b = ('y')
```

The output of type(a) is int, isn't it supposed to be a tuple? Similarly, type(b) is str.

How does this make it an int or str or float etc for the single value inside the round brackets?

Jan 3 in Python 343 views

## 1 answer to this question.

Typecasting is the process of converting one data type into another data type. In Python, typecasting can be done using the following methods:

1. int() - This function is used to convert a number or a string to an integer.

2. float() - This function is used to convert a number or a string to a float.

3. str() - This function is used to convert a number or a boolean value to a string.

4. bool() - This function is used to convert a number or a string to a boolean value (True or False).

For example:

```x = 10
y = "20"

# convert x to a float
z = float(x)

# convert y to an integer
w = int(y)

# convert w to a string
a = str(w)

# convert z to a boolean value
b = bool(z)```

In the above example, the value of x is an integer and it is converted to a float and stored in z. The value of y is a string and it is converted to an integer and stored in w. The value of w is then converted to a string and stored in a. Finally, the value of z is converted to a boolean value and stored in b.

Master the art of Data Science with Python and unlock the power of insights.

• 400 points

## What is the meaning of “int(a[::-1])” in Python?

Assumming a is a string. The Slice ...READ MORE

## What is the meaning of "int(a[::-1])" in Python? [duplicate]

I don't get this at all. In ...READ MORE

## what is the practical use of polymorphism in Python?

Polymorphism is the ability to present the ...READ MORE

## What is the use of raw_input function in Python?

raw_input fuction is no longer available in ...READ MORE

## how can i randomly select items from a list?

You can also use the random library's ...READ MORE

+1 vote

## how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

## Lowercase in Python

You can simply the built-in function in ...READ MORE