
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python program to check if the string is empty or not
In this article, we will learn about the solution and approach to solve the given problem statement.
Problem statement
Given a string input, we need to check if the string is empty or not.
Python strings are immutable in nature so while performing any operations care must be taken while handling strings.
Here we will discuss two approaches to solve the above problem statement −
- Using len() method.
- Using equality operator.
Approach 1: Using len() method
Example
test_str1 = "" test_str2 = "@@@" if(len(test_str2) == len(test_str1)): print ("Yes") else : print ("No")
Output
No
All variables and functions are declared in global scope as shown in the figure below.
Approach 2: Using the equality operator
Example
test_str1 = "" test_str2 = "@@@" if(test_str2 == test_str1): print ("Yes") else : print ("No")
Output
No
All variables and functions are declared in global scope as shown in the figure below.
Conclusion
In this article, we learnt about the approach to find whether a string is a number pangram or not
- Related Articles
- Java Program to check if a string is empty or not
- Golang Program to check the given string is empty or not
- Swift Program to check the given string is empty or not
- Python program to check if a string is palindrome or not
- Java Program to Check if a String is Empty or Null
- Golang program to check if a string is empty or null
- Python program to check whether a list is empty or not?
- Python program to check if a given string is Keyword or not
- Program to check the string is repeating string or not in Python
- C# program to check if string is panagram or not
- Swift program to check if string is pangram or not
- Python Program to check if the tuple is empty
- MySQL query to check if database is empty or not?
- C# program to check if a string is palindrome or not
- Python - Check if a given string is binary string or not

Advertisements