More on Strings in Python Data Science – Day 2
In the previous blog, we will get an idea about functions, data types and typecasting. In this blog, we will get more about strings. You have seen ways to break up strings through use of the split function and through direct indexing.
Strings in Python can be a bit frustrating too, and we want to share some more details of how strings are handles so that you are aware of them. In python 3 strings are Unicode based. In early computing characters of strings were limited to one of 256 different values.
This was enough to get all of the upper or lower cases Latin characters, as well as single-digit numbers represented. This language was called ASCII and was fairly compact.
But the world does not just run on Latin characters and there is a need to support non-English languages as well as characters which are not commonly used in words but are commonly used elsewhere like mathematical operators. The Unicode Transformation Format or UTF is an attempt to solve this.
In addition to Unicode, python uses a special language for formatting the output of strings. one of the challenges with dynamic typing is that it is bit unclear when you have to do type conversion yourself.
We saw on the previous blog that if we wanted to print out a name and a number that we can not use concatenation without calling the str function to convert the number to a string first. The python string formatting allows you to write a strong statement indicating placeholders for a variable to be evaluated.
You then pass these variables in either named or in order arguments, and python handles the strings manipulation for you.
Imagine we have purchase order details and a dictionary, which includes a number of items, a price, and the name of a person. We can write a sales statement string which includes these items using curly brackets.
We can then call the format method on that string and pass in the values that we want to be substituted as appropriate. Now the string formatting languages allow you to do much more than this.
You can control a number of different things like decimal places, for floating-point numbers, or whatever you want to prepend the positive numbers with the plus sign, or set the alignment of stings to left or right justified. Or even enable to use of scientific notation.
You are going to learn a lot more about string manipulation in this series. In the next blog, we will show you how to bring some basic data analysis together through the reading and writing of delimited data files.
VISIT OUR WEBSITE BRIGHTERBEES FOR MORE ABOUT DATA SCIENCE.
CONNECT WITH THE AUTHOR ON LINKEDIN.
IF YOU WANT TO KNOW ABOUT MACHINE LEARNING click here.