Computer Science, asked by satyampathania14, 1 month ago

What is the correct syntax to output the type of a variable or object in Python

Answers

Answered by deshmukhvarsha835
9

Explanation:

you will get the output as <class 'str'>, for the list, it will be <class 'list'>, etc.

Answered by vishakasaxenasl
1

Answer:

Syntax to output the type of a variable

print(type(variable_name)

Explanation:

Python is a loosely typed language which means we don't need to define the data type when we create a variable. The data type will be understood by the interpreter when we assign value to it.

type() Function

  • However, sometimes we might need to know which variable and which data type in our program.
  • And to serve this purpose, Python has a type function.
  • The type function accepts the name of the variable as the parameter and outputs the data type.

For example:

name = "Vishaka"

print(type(name))   #OUTPUT string

num = 123

print(type(num))     #OUTPUT integer

choice = true

print(type(choic)) # OUTPUT boolean

arr = [34,65,'abc'.98.78]

print(type(arr))     #OUTPUT list

#SPJ3

Similar questions