Python capitalize the first letter of every word in a string | Example code

Use title() to capitalize the first letter of every word in a string in python. Python Str class provides a member function title() which makes each word title cased in string. It converts the first character of each word to upper case and all remaining characters of the word to lower case. Example code capitalize Read More…


Python if string equals | Example code

Use the equality (‘==’) operator to check if strings are equal or not. It will work case-sensitive manner i.e. uppercase letters and lowercase letters would be treated differently. Python ‘==’ operator compares the string in a character-by-character manner and returns True if the two strings are equal, otherwise, it returns False. Check if one string Read More…


Python if else one line | Example code

Python if-else one line can be used as a ternary operator. There is the conditional expression. but this is an expression, not a statement. Example code if..else in a single line in Python In python need to convert the if…else statement to a one-line conditional expression. Example of if…else in one line Output: Can we Read More…



Python check for string | Example code

Use the isinstance() method to check for a string in Python. This method can be used to test whether any variable is a particular (string) datatype or not. If yes then return True. Python check for string Example code Python code to demonstrate check if the variable is a string using isinstance(). Output: Another method Read More…


Python string starts with regex | Example code

Series.str.startswith doesn’t accept regex because it is intended to behave similarly to str.startswith in vanilla Python, which does not accept regex. The alternative is to use a regex match. Use Series.str.match instead Python string starts with regex Simple python example code using the re.match(pattern, string) function from the re module. Output: Obviously, in this case, Read More…


Compare two strings Python | Example code

Use comparison operators to compare two strings in Python. Comparison of strings means wants to know whether both strings are equivalent to each other or not. Another thing can do in Comparison to find greater or smaller than the other string. Here some operators will use:- Operators Relational Meaning == Checks two strings are equal Read More…


Python check if the object is string | example code

The best way to checks if the object is a string is by using the isinstance() method in Python. This function returns True if the given object is an instance of class classified or any subclass of class info, otherwise returns False. How to find out if a Python object is a string Example Let’s Read More…


Python print DateTime now | Example code

First, you have to get Today’s date and time then pass this value into a Python Print() function. Example code print DateTime now in Python Use the datetime class of the datetime module to get a DateTime in this task. Output: More specific you can import the datetime object from the datetime module: Then remove Read More…