Remove Last Element from a Set in Python

Vikram Chiluka
Updated on 27-Jan-2023 13:38:08

9K+ Views

In this article, we will learn how to remove the last element from the set in Python. Methods Used The following are the various methods to accomplish this task − Using the discard() function Using the remove() function Using the pop() function Using the list slicing Method 1: Using the discard() function The discard() function removes the element from the set, bypassing the element as an argument to it. Algorithm (Steps) Following are the Algorithms/steps to be followed to perform the desired task. − Create a variable to store the input set containing integers. Use the discard() ... Read More

Accurate Decimal Calculations Using Python

Vikram Chiluka
Updated on 27-Jan-2023 13:36:36

1K+ Views

In this article, we will learn how to perform Accurate Decimal Calculations in Python. Methods Used Using the Decimal() function of the decimal Module Using the fsum() function of the math module The inability of floating-point numbers to accurately represent all base-10 numbers is a well-known drawback. Furthermore, even straightforward mathematical computations have few errors. For instance − Example The following program shows the inability of floating-point integers to express all base-10 numbers accurately − x = 4.2 y = 3.1 # printing the sum of both the variables print("x + y =", x + ... Read More

Manipulating Pathnames Using Python

Vikram Chiluka
Updated on 27-Jan-2023 13:34:09

2K+ Views

In this article, we will learn Manipulating Pathnames using Python. Here are some different examples used mentioned below − Getting the main filename from the file path Getting the directory name from the file path Joining path components together Expanding the User's Home Directory Splitting the file extension from the file path Algorithm (Steps) Following are the Algorithms/steps to be followed to perform the desired task. − Use the import keyword to import the os module. Create a variable to store the input file path. Use the basename() function(returns the base name from the given ... Read More

Iterate Over Tuples in Dictionary Using Python

Vikram Chiluka
Updated on 27-Jan-2023 13:31:22

3K+ Views

In this article, we will learn how to iterate over the tuples in Dictionary in python. Methods Used The following are the various methods used to accomplish this task − Using Indexing Using dictionary.values() Method Using dictionary.items() Method Tuples are an immutable, unordered data type used to store collections in Python. Lists and tuples are similar in many ways, but a list has a variable length and is mutable in comparison to a tuple which has a fixed length and is immutable. Method 1: Using Indexing len() function − The number of items in an object is returned ... Read More

Get File Name from File Path in Python

Vikram Chiluka
Updated on 27-Jan-2023 13:25:13

9K+ Views

In this article, we will learn a python program to get the file name from the file Path. Methods Used The following are the various methods to accomplish this task − Using the OS module functions Using Pathlib Module Using Regular expressions(regex module) Method 1: Using the OS Module Functions Get the File Name From the File Path using the split() Function The split() function splits a string into a list. We can define the separator; the default separator is any whitespace. Algorithm (Steps) Following are the Algorithms/steps to be followed to perform the desired task. − ... Read More

Get Negation of a Boolean in Python

Vikram Chiluka
Updated on 27-Jan-2023 13:22:23

7K+ Views

In this article, we will learn how to get a negation of a Boolean in Python. In Python, the Boolean datatype is the built-in data type. It denotes the True or False values. For example, 520 is False. In this article, we will print the negation of a Boolean variable. The following are the various methods to accomplish this task − Using the “~” operator Using “not” Operator Using Operator Module Using Minus the value from ‘1’ Using bitwise_not(), logical_not() of Numpy Module Method 1: Using the “~” operator The negation of the operand can be returned using ... Read More

Evaluate XPath in the Linux Command Line

Satish Kumar
Updated on 27-Jan-2023 12:53:04

3K+ Views

Introduction XPath is a powerful language used for navigating and selecting elements within an XML document. It is commonly used in conjunction with XSLT, a language used for transforming XML documents, to extract specific information from a document. In this article, we will discuss how to evaluate XPath expressions in the Linux command line, using the command-line tool xmllint. Installing xmllint Before we can begin evaluating XPath expressions in the Linux command line, we must first install xmllint. xmllint is part of the libxml2 library, which is included in most Linux distributions. To check if xmllint is already installed on ... Read More

Remove Last Given Number of Items from Array in Swift

Ankita Saini
Updated on 27-Jan-2023 12:38:26

261 Views

In this article, we will learn how to write a swift program to remove the last given number of items from the array. An array is used to store elements of same data type in an order. So, here we use the following methods to remove the last given number of items from the array − Using removeLast(_:) function Using dropLast(_:) function Using removeSubrange() function Method 1: Using removeLast(_:) Function Swift provide an in-built function named as removeLast() function to remove the specified number of items from the end of the array. Syntax func removeLast(_x: Int) ... Read More

Remove First Given Number of Items from Array in Swift

Ankita Saini
Updated on 27-Jan-2023 12:34:59

511 Views

In this article, we will learn how to write a swift program to remove the first given number of items from the array. An array is used to store elements of same data type in an order. So, here we use the following methods to remove the first given number of items from the array − Using removeFirst(_:) function Using dropFirst(_:) function Using removeSubrange() function Method 1: Using removeFirst(_:) Function Swift provide an in-built function named as removeFirst() function to remove the specified number of items from the start of the array. Syntax func removeFirst(_x: Int) ... Read More

Print Object of a Class in Swift

Ankita Saini
Updated on 27-Jan-2023 12:33:02

2K+ Views

In this article, we will learn how to write a swift program to print object of a class. A class object is known as an instance of a class. For example, colour is a class then obj1, obj2, obj3 and obj4 are the objects from the class. A class can have multiple objects. Syntax var objectname = Classname() Here, using the above syntax we can create an object of a class. Algorithm Step 1 − Create a class with properties and a constructor. Step 2 − Create a function to print the object of the given class. Step ... Read More

Advertisements