Linked Questions
41 questions linked to/from How to check if the string is empty in Python?
25
votes
2
answers
130k
views
How to check if a string is null in python [duplicate]
I have a value cookie that is returned from a POST call using Python.
I need to check whether the cookie value is empty or null.
Thus I need a function or expression for the if condition.
How can I do ...
3
votes
1
answer
566
views
python check string for emptieness - is this the elegant way [duplicate]
if var is not None and var !="" and var !=" ":
# todo
can I write it like this?:
if var:
# todo
var is only String type.
-1
votes
1
answer
4k
views
Why does 'if not ' check empty string in python [duplicate]
Hi I have a quick question regarding 'if not ..' in py.
This is a function that should take a list of strings and return a string.
I wondered what does the first line(if not strs) do? I guess it ...
0
votes
1
answer
2k
views
Validation Rule - User input cannot be left blank - Python [duplicate]
I'm currently working on a program that has a validation rule for a name, which doesn't allow any punctuation to be entered. The input is stored in a variable, name, and then stored in a file later on....
0
votes
1
answer
472
views
How do you detect specifically an integer input but also check to see if the input to something is blank? [duplicate]
I was wondering if it was possible to have an input variable look for an integer input but also be able to detect if the user leaves no input. I was wanting to make a simple app where the user chooses ...
0
votes
4
answers
312
views
Making a simple program, how to I make it so blank/spaces input doesn't count/add to it [duplicate]
I am making a simple program that creates a grocery list. Right now, I am having trouble with blank input being added to my list: when I hit enter with or without spaces, it adds the blank input as ...
0
votes
2
answers
530
views
How to return default value in Python from no user input [duplicate]
I'm trying to have this return a default value of "stupid" if the user does not enter in their name, but I cannot get it to work. It just returns "Greetings " with no name.
def ...
1332
votes
15
answers
1.7m
views
Why does comparing strings using either '==' or 'is' sometimes produce a different result? [duplicate]
Two string variables are set to the same value. s1 == s2 always returns True, but s1 is s2 sometimes returns False.
If I open my Python interpreter and do the same is comparison, it succeeds:
>>&...
169
votes
20
answers
198k
views
Efficient way to remove keys with empty strings from a dict
I have a dict and would like to remove all the keys for which there are empty value strings.
metadata = {u'Composite:PreviewImage': u'(Binary data 101973 bytes)',
u'EXIF:CFAPattern2': u''}...
120
votes
14
answers
618k
views
How to check whether a str(variable) is empty or not?
How do I make a:
if str(variable) == [contains text]:
condition?
(or something, because I am pretty sure that what I just wrote is completely wrong)
I am sort of trying to check if a random.choice ...
7
votes
4
answers
30k
views
Check string "None" or "not" in Python 2.7
Wondering if if not foo is None is the same as if foo? Using Python 2.7 and foo is a string.
6
votes
7
answers
14k
views
Assigning empty value or string in Python
I would like to understand if there is a difference between assigning an empty value and an empty output, as follows:
1> Assigning a value like this
string = ""
2> An empty value returned as output
...
5
votes
5
answers
4k
views
Python: Comparing empty string to False is False, why?
If not '' evaluates to True, why does '' == False evaluates to False?
For example, the "voids" of the other types (e.g. 0, 0.0) will return True when compared to False:
>>> 0 == False
True
&...
1
vote
8
answers
28k
views
Count occurrences of a given character in a string using recursion
I have to make a function called countLetterString(char, str) where
I need to use recursion to find the amount of times the given character appears in the string.
My code so far looks like this.
def ...
-1
votes
11
answers
5k
views
Return empty string as True in given string
def first_and_last(message):
if (message[0] == message[3]):
return True
elif (message[0] != message[3]):
return False
print(first_and_last("else"))
print(...