
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10533 Articles for Python

7K+ Views
Strings are an array of characters that are used to represent a word or any sentence. Strings in Python can be easily used as it does not require any explicit declaration and can be declared without any specifier. Strings in python also have many inbuilt functions and methods to manipulate and access the strings. Since in python everything is an object even String is also an object of the String class and has many methods. In this article, we are going to find out if a given string has only alphabets and numbers without any special symbols using python. We ... Read More

13K+ Views
In this article, we are going to find out how to verify a string that contains only letters, numbers, underscores, and dashes in Python. The first strategy makes use of regular expressions. To use the re library, import it and install it if it isn't already installed. We use the regular expression "^[A-Za-z0-9_-]*$" after importing the re library. If the string contains any special characters other than Alphabets and Numbers, this will return False; otherwise, True will be returned. Example 1 In the example given below, we are taking a string as input and we are checking if it contains ... Read More

5K+ Views
In this article, we are going to find out how to check if a string has at least one letter and one number in Python. Regular expressions is used in the first technique. Import the re library and install it if it isn't already installed to use it. After importing the re library, we can use the regular expression ('^(?=.*[0-9]$)(?=.*[a-zA-Z])'. This will return False if the string contains any special characters other than Alphabets and Numbers; otherwise, True will be returned. In regular expressions, the ?= syntax is used to call lookaheads. Lookaheads discover matches in the provided string by ... Read More

4K+ Views
To check if a string has alphabets or numbers in Python, we can use some built-in methods like isalpha() and isdigit(). isalpha() returns True if all characters in a string are alphabets (letters), and False otherwise. isdigit() returns True if all characters in a string are digits (numbers), and False otherwise. Here are two examples that demonstrate how to check if a string has alphabets or numbers: To Check if a String has Alphabets or Numbers Example In this example, we first prompt the user to enter a string using the input() function. We then check if the string ... Read More

886 Views
In Python, you cannot pass arguments by reference like you can in other programming languages like C++. However, there is a way to simulate pass by reference behavior in Python using mutable data types like lists and dictionaries. In Python, arguments are passed by assignment, which means that the parameter name in the function definition becomes a reference to the object passed as an argument. Therefore, there is no direct way to pass arguments by reference in Python. However, you can achieve a similar effect by passing a mutable object like a list or a dictionary to a function ... Read More

259 Views
For the given code above the solution is as followsExampleclass CustomValueError(ValueError): def __init__(self, arg): self.arg = arg try: a = int(input("Enter a number:")) if not 1 < a < 10: raise CustomValueError("Value must be within 1 and 10.") except CustomValueError as e: print("CustomValueError Exception!", e.arg)OutputEnter a number:45 CustomValueError Exception! Value must be within 1 and 10. Process finished with exit code 0

781 Views
A suffix is defined as a letter or group of letters added at the end of a word to make a new word. Let's say you have a list of suffixes, which are groups of letters that can be added to the end of a word to change its meaning. You want to check if a given string ends with one of these suffixes in Python. To check if a string ends with a suffix in a list Example In this example, we first define a list of suffixes that we want to check if the string ends with. ... Read More

2K+ Views
To check if a string or a substring of a string ends with a suffix in Python, there are several ways to accomplish this. Here are some examples: Using the endswith() Method The endswith() method checks if the string ends with a specified suffix and returns a boolean value. To check if a substring of a string ends with a suffix, you can use string slicing to get the substring and then apply endswith() on it. Example string = "hello world" suffix = "world" if string.endswith(suffix): print("String ends with suffix") Output String ends with ... Read More

889 Views
All python exceptions are not runtime errors, some are syntax errors as well.If you run the given code, you get the following output.File "C:/Users/TutorialsPoint1/~.py", line 4 else: ^ SyntaxError: invalid syntaxWe see that it is syntax error and not a runtime error.Errors or inaccuracies in a program are often called as bugs. The process of finding and removing errors is called debugging. Errors can be categorized into three major groups:Syntax errors 2. Runtime errors and 3. Logical errorsSyntax errorsPython will find these kinds of errors when it tries to parse your program, and exit with an error message without running ... Read More