How to remove newlines from a string in Python 3?

Problem We would like to delete automatically appended newlines added to a string using Python 3 code. Solution We have two methods to delete the newline from a string. In this post we’ll discuss each technique and obviously post the required code. Using rstrip() method: The rstrip() method removes any trailing character at the end … Read more

How to get the length of a string in Python?

Problem To calculate and print the length of a provided string of characters / words using Python 3. Solution There are many simple ways to find the length of a string in Python. We will discuss some of those techniques in this short tutorial, alongside with the required Python 3 code. Using len() function: The … Read more

How to remove a character from a string in Python 3?

In this tutorial we would like to show you how to remove a specific character from a string using Python. We have many techniques to remove a character from the string. Today, we’ll cover the following cases: removing the first, last, and any specific characters from the provided character / word strings alongside with the … Read more

How to print a string in reverse in Python 3?

Problem We would like to turn upside down a string and print it in reverse mode in Python. Solution We have many different methods to approach to reverse a string in Python. Let’s look at each technique one by one in this post. Using Extended Slicing technique: We can obtain with the reverse of a … Read more

How to open and read an excel file with Python?

Problem Working with spreadsheets is essential when dealing with data. In this tutorial we would like to show you how to open and read excel worksheets (xls / xlsx file formats) using Python 3. Solution We have two libraries in Python that can help us to work with the excel sheet. We will discuss more … Read more

How to write text files in Python 3?

Problem: A very common development task is to work with text files, specifically create the file as well as read and write data into it. Solution: Python delivers built-in functions to create and manipulate text files. We will also show you that we are able to append text after the file is created. Let’s look … Read more

How to convert a Python string to Hex format?

Problem To convert a string data type to an Hexadecimal number format in Python 3.X. Solution We have two methods to convert a python string to a Hex value. Using int() function and by importing literal_eval from the ast Python module. In this post, we will learn how we can convert a string to a Hexadecimal number.  … Read more

Find the sum of all elements in a Python list

Problem: To take and sum all the elements present in a Python integer or float numbers list. Solution: We have three different methods to achieve the solution. In this post, we will look at all three methods to sum the numbers in a list. Option 1: Python Sum() Function: Python has an inbuilt function sum(), … Read more