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 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

How to round up a float number in Python?

Problem: Today, we’ll learn how to round up float numbers using Python. Solution: We have two methods to handle the rounding float numbers in Python. Using the round() function and Decimal module. We will look at the solutions with examples for each method in this post. Option 1: Python Round Function Python has an inbuilt function round(), which … Read more