• Register
0 votes
36 views

I am new to python programming.. I was trying to check if a string is empty or whitespace in a code :

Mystr= ""
Yourstr = "   "

print ("This string is empty : ", end = "") 
if(not Yourstr): 
    print ("Yes") 

  
  
print ("This string is empty : ", end = "") 
if(not Mystr): 
    print ("No") 

 It’s output is :

This string is empty : This string is empty : No

Its not giving me actual result what can I do now?

10 7 2
6,060 points

Please log in or register to answer this question.

1 Answer

0 votes

In your code you should have used else statement with your if sattement. You should write your code like:

Mystr= ""
Yourstr = "   "

print ("This string is empty : ", end = "") 
if(not Mystr): 
    print ("Yes") 
else : 
    print ("No") 
  
  
print ("This string is empty : ", end = "") 
if(not Yourstr): 
    print ("Yes") 
else : 
    print ("No") 

and your ouput will be:

This string is empty : Yes
This string is empty : No

 

11 6 4
34,950 points

Related questions

1 vote
1 answer 4 views
4 views
Problem: Please help me to solve it out : python check if string is empty or whitespace
asked Mar 30 MUHAMMAD MUNEEB 83k points
0 votes
1 answer 27 views
27 views
I am new to python programming I was trying to check if a letter is uppercase in python. I wrote some code to check this statement : import string def UpperCase(s_str): for x in s_str: if x not in string.UpeerCase: return False return True But I can not get the actual ... last): File "<stdin>", line 1, in <module> NameError: name 'LoWWE' is not defined Can anyone help me to solve this thing?
asked Mar 14, 2020 LizzyM 6.1k points
1 vote
1 answer 42 views
42 views
Problem: I am new in pyhton programing language . I was trying to check if two strings are anagrams python. But I fail repitedly. The code I wrote to check if two strings are anagrams is: def IsAnagram(str1,str2): str1 = input("Enter your first string : ") ... , line 4 str1 = input("Enter your first string : ") ^ IndentationError: expected an indented block What is the problem can anyone tell?
asked Apr 2, 2020 LizzyM 6.1k points
1 vote
1 answer 749 views
749 views
Problem: I am getting the following error : error: array initializer must be an initializer list or string literal For the array; char x[80] = GetString(); Can any body explain or help?
asked Apr 2, 2020 LizzyM 6.1k points
0 votes
1 answer 153 views
1 vote
1 answer 69 views
69 views
Problem: I am beginner in pyhton prgramming language, I tried to convert string array to int array using python so I wrote a code which contains- testing_list = ['4', '2', '3', '9', '5'] And my code is: testing_list = ['4', '2', '3', '9', '5 ... list is : str(testing_list) Converted list is : str(testing_list) why am I not getting the converted result and what is the way to get the acurate result?
asked Mar 29, 2020 LizzyM 6.1k points
1 vote
1 answer 26 views
26 views
Problem: I was tring to find the length of a string in python. So I wrote a code: string = 0 for c in "popular": string+==1 print (string) which gives following error; File "ab.py", line 3 string+==1 ^ SyntaxError: invalid syntax Is this the right way to do this or there are other waysto find this out?
asked Mar 28, 2020 LizzyM 6.1k points
0 votes
1 answer 6 views
6 views
Problem: how to I Solve this: python remove whitespace from start and end of string HELP! I need help understanding this: python remove whitespace from start and end of string Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
asked Mar 8 Mashhoodch 13k points
0 votes
1 answer 5 views
5 views
Problem: how to I Solve this: python remove whitespace from end of string HELP! I need help understanding this: python remove whitespace from end of string Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
asked Mar 8 Mashhoodch 13k points
1 vote
1 answer 17 views
17 views
Problem: For the following code where I was checking a string that consists a empty string python: Firststring= "" Secoendstring = " " print ("Your string is empty : ", end = "") if(not Secoendstring): print ("Yes") print ("Your string is empty : ", end = "") if(not ... . Can any one tell me why am I getting this type of result and how can I fix my code to get the exact result. Thanks in advance.
asked May 4, 2020 samhaz 5k points