Write a python function to convert given variable to said datatype


Topic: Write a python function to convert given variable to said datatype

Solution

def type_conversion(typ,a):
  if(typ)=='int':
    return(int(a))
  elif(typ)=='float':
    return(float(a))
  else:
    return(str(a))
type_conversion('str',1)



List all Python Programs