Given a string s, write a method (function) that will return true if its a valid single integer or floating number or false if its not.

Valid examples, should return true:

should return false:

Difficulty: EASY
Starter code: def isDigit(string):
	

Solutions:
def isDigit(string):
	try:
		float(string)
		return True
	except:
		return False


def isDigit(strng):
	try:
		float(strng)
		return True
	except ValueError:
		return False


def isDigit(string):
	return string.lstrip('-').replace('.', '').isdigit()


from re import match

def isDigit(string):
	return bool(match('^[-+]?\\d+\\.?\\d*?$', string))


def isDigit(string):
	try:
		int(string) or float(string)
	except ValueError:
		try:
			float(string)
		except ValueError:
			return False
	return True


def isDigit(string):
	try:
		return bool(float(string)) or True
	except:
		return False


import re

def isDigit(string):
	return True if re.match('^-?\\d*\\.?\\d+$', string) else False


import re

def isDigit(string):
	return bool(re.search('^-?[\\d\\.]+$', string))


def isDigit(string):
	try:
		return isinstance(float(string), float)
	except:
		return False


def isDigit(string):
	try:
		type(float(string.strip()))
	except ValueError:
		return False
	return True


def isDigit(string: str) -> bool:
	try:
		float(string.strip())
		return True
	except ValueError:
		return False


def isDigit(string):
	try:
		a = float(string)
	except:
		return False
	else:
		return True


def isDigit(string):
	string.strip('-')
	string.strip
	try:
		string = int(string)
		return True
	except ValueError:
		pass
	try:
		string = float(string)
		return True
	except ValueError:
		return False


def isDigit(s):
	try:
		return type(int(float(s))) == int
	except:
		return False


def isDigit(str):
	try:
		float(str)
	except ValueError:
		return False
	return True


import re

def isDigit(string):
	try:
		float(string)
		return True
	except ValueError:
		pass
	try:
		int(string)
		return True
	except ValueError:
		pass
	return False


import re

def isDigit(s):
	return re.match('^(-?)(([0-9]+\\.[0-9]+)|([0-9]+))$', s) is not None


def isDigit(string):
	if len(string) == 0 or string[0] not in '-+.0123456789':
		return False
	for char in string[1:]:
		if char not in '.0123456789':
			return False
	return True


def isDigit(string):
	import re
	string = string.strip()
	return bool(re.match('^-?\\d*\\.{0,1}\\d+$', string))


def isDigit(string):
	str = string.strip()
	if len(str) == 0:
		return False
	if str[0] == '-':
		str = str[1:]
	if len(str) == 0:
		return False
	if str[0] == '.' or str[-1] == '.':
		return False
	digit = [s for s in str if s in '0123456789.']
	return True if len(digit) == len(str) else False


import re

def isDigit(string):
	return True if re.search('(^-*[0-9\\.]+$)', string) else False


def isDigit(s):
	try:
		return 0.1 != float(s)
	except:
		return False


def isDigit(string):
	s = string.replace('-', ' ').strip()
	try:
		s = eval(s)
		return 1
	except:
		return 0


def isDigit(string):
	try:
		x = list(str(string.strip()))
		if '.' in x:
			return type(float(string.strip())) == float
		else:
			return type(int(string.strip())) == int
	except:
		return False


def isDigit(string):
	string = string.strip()
	if len(string) < 1:
		return False
	if string[0] not in '0123456789-':
		return False
	index_point = -1
	if string.count('.') > 1:
		return False
	elif string.count('.') == 1:
		index_point = string.find('.')
		if string[0] == '-':
			if string[1:index_point].isdigit() and string[index_point + 1:].isdigit():
				return True
			else:
				return False
		elif string[0:index_point].isdigit() and string[index_point + 1:].isdigit():
			return True
		else:
			return False
	elif string[0] == '-':
		return string[1:].isdigit()
	else:
		return string.isdigit()


def isDigit(string):
	return all((i.isdigit() or i == '.' for i in (string[1:] if string[0] == '-' else string))) if string else False


def isDigit(string):
	ans = True
	cd = 0
	if string == '':
		return False
	if string[0] == '-':
		string = string[1:]
	for i in string:
		if i == '.':
			if cd >= 1:
				ans = False
			else:
				cd += 1
		else:
			try:
				int(i)
			except:
				ans = False
	return ans


def isDigit(string):
	return string.lstrip('+-').isdigit() or string.lstrip('+-').replace('.', '', 1).isdigit()


def isDigit(string):
	if len(string) < 0:
		return False
	else:
		try:
			float(string)
		except:
			return False
		else:
			return True


def isDigit(string):
	new = ''.join(string.strip())
	try:
		float(new)
		return True
	except:
		return False


def isDigit(st):
	try:
		if int(st.strip()) == 0 or int(st.strip()):
			return True
	except ValueError:
		try:
			if float(st.strip()) or float(st.strip()) == 0.0:
				return True
		except ValueError:
			return False


def isDigit(string):
	string = string.replace('0', '').strip()
	try:
		if float(string) or int(string):
			return True
	except:
		if string == '-' or string == '.':
			return True
		return False


def isDigit(string):
	a = 0
	if string == '':
		return False
	for i in string:
		if i.isalpha():
			a += 1
		elif '-' in string[1:]:
			a += 1
		elif i == ' ':
			a += 1
	if a == 0:
		return True
	else:
		return False


def isDigit(string):
	try:
		return type(float(string)) is float
	except ValueError:
		return False


def isDigit(s):
	if s.isalnum():
		return False
	k = s.isnumeric() or is_number(s)
	return k

def is_number(s):
	try:
		float(s)
		return True
	except ValueError:
		return False


def isDigit(string):
	try:
		str2 = string.strip()
		return str2.isdigit() or abs(int(float(str2))) >= 0
	except TypeError:
		return False
	except ValueError:
		return False


import re

def isDigit(string):
	return re.fullmatch('\\-{0,1}\\d+(\\.\\d+){0,1}', string) != None


def isDigit(string):
	string.strip()
	string = string.replace('.', '')
	try:
		int(string)
		return True
	except:
		return False


def isDigit(string):
	try:
		float(string)
		return True
	except ValueError:
		return False
	return string.isdigit()


def isDigit(string):
	string = string.lstrip(' -').rstrip(' ').replace('.', '', 1)
	return string.isdigit()


import re

def isDigit(string):
	print(string)
	return bool(re.match('^-?\\d*\\.?\\d+$', string))


def isDigit(string):
	try:
		resultado = float(string)
		return True
	except ValueError:
		return False


def isDigit(s):
	try:
		float(s.strip())
	except:
		return False
	return True


def isDigit(string):
	string = string.replace('.', '')
	string = string.strip()
	if string and string[0] == '-':
		string = string.replace('-', '')
	return string.isdigit()


def isDigit(string):
	try:
		float(string.strip())
		return 1
	except:
		return 0


def isDigit(string):
	try:
		test = int(string)
		return True
	except:
		pass
	try:
		test = float(string)
		return True
	except:
		return False


def isDigit(s):
	try:
		float(s)
		return True
	except:
		pass
	return False


def isDigit(n):
	try:
		return type(float(n)) == float
	except:
		return False


def isDigit(string):
	return True if string.lstrip('-').replace('.', '', 1).isdigit() else False


def isDigit(string):
	string = string.replace('.', '')
	if string:
		if string[0] == '-':
			string = string[1:]
		return string.isnumeric()
	else:
		return False


def isDigit(string):
	potential_digit = string.strip()
	try:
		digit = float(potential_digit)
	except:
		return False
	else:
		return True


def isDigit(string):
	if string.isdigit():
		return True
	try:
		float(string)
		return True
	except:
		return False
	else:
		return False


def isDigit(string):
	return string.lstrip('-').replace('.', '', 1).isnumeric()


def isDigit(string):
	try:
		return True if float(string) + 1 else False
	except:
		return False


def isDigit(string):
	clean_string = string.strip()
	if string == '-0':
		return True
	print(clean_string)
	try:
		if str(int(clean_string)) == clean_string:
			return True
	except:
		pass
	try:
		if str(float(clean_string)) == clean_string:
			return True
	except:
		return False


def isDigit(string):
	has_dot = False
	for char in string:
		if char == '.':
			has_dot = True
	if has_dot:
		try:
			digit = float(string)
		except:
			return False
	else:
		try:
			digit = int(string)
		except:
			return False
	return True


def isDigit(string):
	try:
		k = int(string)
	except:
		try:
			k = float(string)
		except:
			k = 'nope'
	return True if type(k) == int or type(k) == float else False


def isDigit(string):
	print(string)
	s = string.lstrip('-')
	print(s.isdigit())
	print(s.isdecimal())
	print(s.isnumeric())
	try:
		float(s)
		print('succes')
		return True
	except:
		return False


import re

def isDigit(str):
	return bool(re.match('^([-]?\\d+\\.\\d+|\\d+|-0)$', str))


def isDigit(string):
	try:
		if float(string) + 1.0:
			return True
	except ValueError:
		return False


def isDigit(string):
	if string == '':
		return False
	s = string.split('.')
	if s[0][0] == '-':
		if len(s) == 2:
			if s[0][1:].isdigit() and s[1].isdigit():
				return True
		elif s[0][1:].isdigit():
			return True
	elif len(s) == 2:
		if s[0].isdigit() and s[1].isdigit():
			return True
	elif s[0].isdigit():
		return True
	return False


def isDigit(string):
	try:
		return type(int(float(string))) == int
	except Exception:
		return False


def isDigit(number):
	try:
		test = int(number)
	except:
		try:
			test1 = float(number)
		except:
			return False
	return True


import re

def isDigit(s):
	return bool(re.match('^-*\\d+\\.*\\d*$', s))


def isDigit(string):
	try:
		return True if type(float(string)) == float else False
	except:
		return False


def isDigit(string):
	return string.replace('.', '').strip('-').isdigit()


def isDigit(s):
	if s == '3-4':
		return False
	a = s.replace('-', '').replace('.', '')
	return a.isdigit()


def isDigit(s):
	try:
		s = float(s)
		return True
	except ValueError:
		return False


def isDigit(s):
	try:
		float(s)
		return True
	except Exception:
		return False


def isDigit(string):
	print(string)
	first_hit = 0
	hit = False
	for val in string:
		if val >= 'a' and val <= 'z' or (val >= 'A' and val <= 'Z'):
			return False
		if val >= '0' and val <= '9' and (first_hit == 0):
			first_hit += 1
		if first_hit and val == ' ':
			first_hit += 1
		if first_hit > 1 and val >= '0' and (val <= '9'):
			first_hit += 1
			hit = True
	if string == '3-4':
		return False
	if hit or first_hit == 0:
		return False
	return True


def isDigit(string):
	print(string)
	try:
		a = float(string)
		return True
	except:
		return False


def isDigit(string):
	try:
		string = string.strip(' ')
		try:
			k = int(string)
		except:
			float(string)
		return True
	except:
		return False


import unicodedata

def isDigit(string):
	try:
		float(string)
		return True
	except ValueError:
		pass
	try:
		unicodedata.numeric(string)
		return True
	except (TypeError, ValueError):
		pass
	return False


def isDigit(string):
	truth = False
	try:
		if type(int(string)) is int:
			truth = True
	except ValueError:
		truth = False
	try:
		if type(float(string)):
			truth = True
	except ValueError:
		truth = False
	return truth


def isDigit(string):
	if string == '':
		return False
	elif string[0] == '-':
		return string.replace('-', '', 1).replace('.', '', 1).isdigit()
	else:
		return string.replace('.', '', 1).isdigit()


def isDigit(string):
	decnumber = 0
	str = string.strip()
	if len(str) < 1:
		return False
	if '-' == str[0]:
		str = str[1:]
	for character in str:
		if not character.isdigit() and character != '.':
			return False
		if character == '.':
			decnumber = decnumber + 1
		if decnumber > 1:
			return False
	return True


def isDigit(string):
	string = string.strip()
	try:
		i = float(string)
		return True
	except:
		return False


def isDigit(string):
	numbers = '-0123456789.'
	str_num = ''
	if string.strip() == '':
		return False
	else:
		x = string.strip()
		y = x[0]
		for (i, char) in enumerate(x):
			if char in numbers:
				if y == '-' and char == x[0]:
					str_num += char
				elif x[i] == 0 or char != '-':
					str_num += char
				else:
					return False
			else:
				return False
		return True


import re
DECIMAL_NUMBER_PATTERN = re.compile('[+-]?((\\.\\d+)|(\\d+\\.?\\d*))')

def isDigit(string: str) -> bool:
	return DECIMAL_NUMBER_PATTERN.fullmatch(string) != None


def isDigit(string):
	string = string.strip()
	try:
		num = float(string)
		return True
	except:
		return False


import re

def isDigit(string):
	return False if re.match('^[-+]?([0-9]+(\\.[0-9]+)?|\\.[0-9]+)$', string.strip()) is None else True


def isDigit(string):
	string = string.strip(' -')
	try:
		convert = float(string)
		return True
	except:
		return False


def isFloat(x):
	try:
		float(x)
		return True
	except ValueError:
		return False

def isDigit(string):
	return isFloat(string)