473,320 Members | 1,910 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to find a number is a digit or not?

440 256MB
Hi,

Without using list ,How to find a number is a digit or not?.Is there any global function is availabe in Python which says the number is a digit.

Thanks in advance
PSB
Mar 7 '07 #1
3 9868
bartonc
6,596 Expert 4TB
Hi,

Without using list ,How to find a number is a digit or not?.Is there any global function is availabe in Python which says the number is a digit.

Thanks in advance
PSB
How 'bout:
>>> "a".isdigit()
False
>>> "1".isdigit()
True
>>> "123".isdigit()
True
>>>
>>> help(str)
Help on class str in module __builtin__:

class str(basestring)
| str(object) -> string
<snip>
Mar 7 '07 #2
bartonc
6,596 Expert 4TB
Hi,

Without using list ,How to find a number is a digit or not?.Is there any global function is availabe in Python which says the number is a digit.

Thanks in advance
PSB
I often wrap this in a try block:
Expand|Select|Wrap|Line Numbers
  1. try:
  2.     a = int(numStr)
  3. except ValueError:
  4.     a = 0
Mar 7 '07 #3
ghostdog74
511 Expert 256MB
isdigit() is usually the best way to check for digit.
you also can use re to check.
eg
Expand|Select|Wrap|Line Numbers
  1. >>> import re
  2. >>> a = "123"
  3. >>> if re.findall("\D+",a):
  4. ...  print "Not digit"
  5. ... else:
  6. ...  print "digit"
  7. ...
  8.  
Mar 7 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: Bern | last post by:
how to specifiy a binary number in c++? hex numbers are specified by 0x prefix
1
by: Maq | last post by:
What I must to change in: #include <vector> #include <_str.h> #include <stdio.h> #include <ctype.h> void f_1(int a, int b) { printf ("f_1\n"); printf ("%d",b); scanf ("%d",&a);
3
by: kathy | last post by:
I want to know what is the easy way to check if a string is a number or not? the number can be int, float, double, scientific,... what is the easy way for only interger?
5
by: MN | last post by:
Hello, I have a customer table and another table that I need to prepopulate with special customer IDs, unique and not sequential. Is there a way to configure Access to assign the customer ID to...
14
by: dharmdeep | last post by:
Hi friends, I need a sample code in C which will convert a Hexadecimal number into decimal number. I had written a code for that but it was too long, I need a small code, so request u all to...
17
by: rhitz1218 | last post by:
Hi, I'm trying to create a function that will sort a number's digits from highest to lowest. For example 1000 - will become 0001 or 1234 to 4321
3
by: Kris | last post by:
I need to create a valid mod10 or luhn number that can be attached to an invoice, I have found several examples showing how to validate a credit card number or validate a number using mod10/luhn. ...
5
debasisdas
by: debasisdas | last post by:
A ten-digit number contains every digit from 0 to 9. The digits are arranged so that the number formed by the first two digits, reading from left to right, is divisible by 2, the number formed by...
2
by: xp5 | last post by:
Hi, I'm trying to find the total number of digit for a user's input integer. I'm using the sizeof() function but keeps getting the size is 4 for some odd reason. For example sizeof(32333)...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.