0 votes
in Python Flask by
How will you check if all characters in a string are alphanumeric?

1 Answer

0 votes
by
For this, we use the method isalnum().

Q.14. How will you capitalize the first letter of a string?

Simply using the method capitalize().

>>> 'ayushi'.capitalize()
‘Ayushi’

>>> type(str.capitalize)
<class ‘method_descriptor’>

However, it will let other characters be.

>>> '@yushi'.capitalize()
‘@yushi’

>>> 'Ayushi123'.isalnum()
True

>>> 'Ayushi123!'.isalnum()
False

Other methods that we have include:

>>> '123.3'.isdigit()
False

>>> '123'.isnumeric()
True

>>> 'ayushi'.islower()
True

>>> 'Ayushi'.isupper()
False

>>> 'Ayushi'.istitle()
True

>>> ' '.isspace()
True

>>> '123F'.isdecimal()
False

Related questions

0 votes
asked Oct 4, 2023 in JavaScript by GeorgeBell
+2 votes
asked Jul 28, 2019 in R Language by Aarav2017
...