Python Articles

Page 839 of 855

How to work with a text file in Python?

Pranathi M
Pranathi M
Updated on 11-May-2023 2K+ Views

For creating, reading, updating, and removing files, Python includes a number of functions. When reading or writing to a file, the access mode determines the kind of operations that can be performed on the file. Creating a file using Python To create new files or open existing files, we can use the open() function. This function accepts two parameters: a string value representing the name of the file you need to create and a character representing the access mode of the file that is to be created. Following is the syntax of this function. File = open("txt_file_name" ,"access_mode") ...

Read More

What are the differences between list, sequence and slice data types in Python?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 08-May-2023 3K+ Views

We will learn about the differences between list, sequence, and slice data types in Python in this article. Lists − In Python, a list is a type of data that can hold multiple values in a single variable. You can think of it like a shopping list that contains multiple items. For example, you could have a list of numbers like [1, 2, 3, 4, 5] or a list of names like ["John", "Jane", "Bob", "Sue"]. Number_List = [1, 2, 3, 4, 5] Name_List = ["John", "Jane", "Bob", "Sue"] Sequences − In Python, a sequence is a type of data ...

Read More

How to escape any special character in Python regular expression?

Md Waqar Tabish
Md Waqar Tabish
Updated on 04-Apr-2023 2K+ Views

Regex, often known as regexp, is a potent tool for finding and manipulating text strings, especially when processing text files. Regex may easily replace many hundred lines of computer code with only one line. All scripting languages, including Perl, Python, PHP, JavaScript, general-purpose programming languages like Java, and even word processors like Word, support Regex for text searching. Regex may be challenging to learn because of its complicated syntax, but it is time well spent. Special Characters Text processing becomes more challenging when special characters are included because context must be carefully considered. You must think about what you see, ...

Read More

How does del operator work on list in Python?

Pranav Indukuri
Pranav Indukuri
Updated on 04-Apr-2023 928 Views

Lists are one of the four most commonly used data structures provided by Python. A list is a data structure in python that is mutable and has an ordered sequence of elements. Following is a list of integer values. lis= [1, 2, 3, 4, 5] print(lis) If you execute the above snippet, it produces the following output. [1, 2, 3, 4, 5] In this article, we will learn how a del operator works on a list in python. They are various scenarios where we use the del operator. The del operator The del keyword is mostly used in ...

Read More

What is correct name of * operator available in Python?

Vikram Chiluka
Vikram Chiluka
Updated on 09-Nov-2022 353 Views

In this article, we will explain the correct name of the * operator available in python. In Python, you'll encounter the symbols * and ** used frequently. Many Python programmers, especially those at the intermediate level, are confused by the asterisk (*) character in Python. The *args argument is called the "variable positional parameter" and **kwargs is the "variable keyword parameter". The * and ** arguments just unpack their respective data structures.Using Asterisk ( * ) Operator in Multiplication  Algorithm (Steps) Following are the Algorithm/steps to be followed to perform the desired task − Create two variables and ...

Read More

How can I represent an infinite number in Python?

Vikram Chiluka
Vikram Chiluka
Updated on 09-Nov-2022 12K+ Views

In this article, we will show you how to represent an infinite number in python. Infinity is an undefined number that can be either positive or negative. A number is used to represent infinity; the sum of two numeric values may be a numeric but distinct pattern; it may have a negative or positive value. All arithmetic operations on an infinite value, whether sum, subtraction, multiplication or any other operation, always result in an infinite number. In the field of computer science, infinity is commonly used to evaluate and optimize algorithms that do calculations on a huge scale. Infinity in ...

Read More

How to Find HCF or GCD using Python?

Vikram Chiluka
Vikram Chiluka
Updated on 28-Oct-2022 2K+ Views

In this article, we will show you how to find the HCF (Highest Common Factor) or GCD (Greatest Common Factor) in Python. Below are the various methods to accomplish this task: Using For Loop Using Euclidean Algorithm Using While Loop Using Recursion(Naive method) Handling Negative Numbers in HCF What is H.C.F. or G.C.D? The largest positive integer that perfectly divides the two given numbers is known as the highest common factor (H.C.F.) or greatest common divisor (G.C.D.). Example - The HCF of 12 and 14, is 2. Using For Loop Algorithm (Steps) Following are the Algorithm/steps to be followed to ...

Read More

How can I generate random integers between 0 and 9 using Python?

Vikram Chiluka
Vikram Chiluka
Updated on 28-Oct-2022 4K+ Views

In this article, we will show you how to generate random integers between 0 and 9 in Python. Below are the various methods to accomplish this task: Using randint() method Using randrange() method Using secrets module To generate random integers within certain ranges, Python supports a variety of functions. We will discuss Python's built-in random module for generating random numbers. The two primary functions provided by the random module to produce random integers are randint() and randrange(). In order to produce random values, a second module called secrets is also used. Using randint() method The random.randint() method is ...

Read More

How to Transpose a matrix in Single line in Python?

Vikram Chiluka
Vikram Chiluka
Updated on 27-Oct-2022 2K+ Views

In this article, we will show you how to transpose a matrix in a single line in python. Below are the various ways to accomplish this task − Using Nested List Comprehension Using NumPy Module Using zip() Function What is the transpose of the matrix? A matrix transpose is the interchanging of rows and columns. It is abbreviated to A'. The element in the ith row and jth column of A' will be moved to the jth row and ith column of A' Using Nested List Comprehension Algorithm (Steps) Following are the Algorithm/steps to be followed to ...

Read More

How to Convert Decimal to Binary Using Recursion in Python?

Vikram Chiluka
Vikram Chiluka
Updated on 27-Oct-2022 3K+ Views

In this article, we will show you how to convert decimal to binary using recursion in python. A decimal number is the most familiar number system to the general public. It is base 10 which has only 10 symbols − 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. Whereas Binary number is the most familiar number system to digital systems, networking, and computer professionals. It is base 2 which has only 2 symbols: 0 and 1, these digits can be represented by off and on respectively. When we convert a number from the decimal number system to ...

Read More
Showing 8381–8390 of 8,549 articles
« Prev 1 837 838 839 840 841 855 Next »
Advertisements