what does python think about B > A [duplicate] - python

This question already has answers here:
How are strings compared?
(7 answers)
Closed 1 year ago.
comparison of letter of alphabet
if "b" > "a":
print("greater")
is python going to evaluate them in order they appear in alphabet?
what if i evaluate a letter like a with a number?
will it be according to ASCII?

Yes.
Here are a few examples:
And for your convenience, the ASCII table:

Related

Curious about the function of ~in the following code [duplicate]

This question already has answers here:
The tilde operator in Python
(9 answers)
Closed 1 year ago.
pd_selftest = pd_selftest[pd_selftest['SICCD'] != 0]
pd_selftest = pd_selftest[~pd_selftest['SICCD'].isnull()]
I'd like to know what the function of the ~ is in the above code.
That's the bit-wise invert or not operator. So, it returns only those lines where the SICCID column is not null. I would probably use the word not in this case.

Getting value component in python? [duplicate]

This question already has answers here:
Python - Split integer into individual digits (undetermined amount of digits)
(4 answers)
Closed 1 year ago.
I cannot describe clearly because English is not my native language
If I input like this
a = 4252
Then I want to take each number component, it should be like this
a1=4; a2=2; a3=5; a4=2
How to do that in python?
If you know it has a similar question in stackoverflow, give me a link
Convert the integer to a string for easy iterability then get the int value of every character like this: a1,a2,a3,a4 = [int(elem) for elem in str(a)]

Is there any syntax in Python to check whether an integer input by the user contains a specific digit in it? [duplicate]

This question already has answers here:
How to check if a specific digit is in an integer
(5 answers)
Closed 2 years ago.
So I basically want to know whether there is any syntax that can recognize if the integer entered by the user contains some specified digit
For example: 23 has the digit 3.
Convert the digit to a string, then check if the digit is in the string.
For example, I want to check if 9 is in the number.
x = str(50192301)
if '9' in x:
return True

Why it shows True if I type print('a'>'A')? [duplicate]

This question already has answers here:
How are strings compared?
(7 answers)
Why does Python sort put upper case items first?
(3 answers)
Closed 2 years ago.
print('a'>'A')
why it shows "True" result what is the logic??
Look up the ordinals for these characters -- the position in the ASCII or Unicode table for each character or code point:
>>> ord('a')
97
>>> ord('A')
65
>>> print('a'>'A')
True
97 is greater than 65. Thus, a comes after A.
See Sort dictionary by key using locale/collation for discussion of how comparison can be done according to locale-specific collation order instead.

Converting a string to a numerical value [duplicate]

This question already has answers here:
How to extract a floating number from a string [duplicate]
(7 answers)
Closed 8 years ago.
I wander if there is a simple way to convert a string to a number, knowing that the string begins with numbers but can contain non numerical characters.
For example: my_str = "36.12minuts"
I remember a function in Visual Basic that does the conversion directly :
my_str = "36.12minuts"
val(my_str) => 36.12
How about Python?
def digitsndots(text):
if text in ["1","2","3","4","5","6","7","8","9","0","."]:
return True
else:
return False
num = float(filter(digitsndots, "36.12minuts"))
print num
When using this make sure your string does not have digits in between like "1.a.34.c" (courtesy of #Taha)

Categories

Resources