Saturday, 27 November 2021

Sequence Data Part 5 | Day 9 | General Sequence Data Methods | Part I


General Sequence Data Methods | Part I


Some of the methods that we can apply on any sequential data.

So basically Python methods are like a Python function, but it must be called on an object.
And Python also has a set of built in methods that you can use on sequential data, but note that the method is going to written new values, but they are not going to change the original data at all. So we are going to look at few examples on how we can call the methods on the given sequential data
.





First I am creating a string for strsample which has a string to with that is learning is fun. So let
me first print and show you. So, the strsample contains string learning is fun.

String Methods


1) .capitalize() - So let us try to call some of the methods on the string but note here all string method returns new value. We do not change the original string. First we are going to look here is method capitalise and it is going to return the string with the first character capitalise. So let us just try this. So initially it was learning is fun and lowercase and now it is learning is fun with the upper case L.





2) .title() - Next one is title, basically capitalise the first character of each word. So if you have a sequence of values, if you have a string if you have set of strings in your data and if you want to do some of the operations like this then you can use all these methods on your string. So for example now, if you want to capitalise the first character of each word, then you can use title method in that case. So, it is going to written the values by capitalising the first character alone.





3) .swapcase() - And thus a method calls what case which is going to swap the
case of strings. So if it is a lowercase string then it is going to swap it to make it as uppercase string. So the original string had the learning is fun in all lowercase letters, but just what all the characters to uppercase.



4) .find()
And you can also find the index of a given letter, for example, if you want to particularly know the index of a given character then you can give that inside the find method. So that should be given the single quote. So the index of n is 4.




5) .count() - So if you want to count the total number of particular letter in a given string then you can use the count method. And inside the count method you can just give the desired string value. So that is one because a is present only ones. For example here is there in the word learning only once



6) .replace() - Using the method replace you will be able to replace any word with the given word. For example, you can apply or you can call that on the string and that is strsample and inside method you can just give string to be searched that is fun. So we are searching for the word fun in the strsample string and I am going to replace fun with joyful. So let me just try this. So you are getting learn is joyful. Instead of getting learn is fun which was the original string.




The below code will show all the functions that we can use for the particular variable:




len(object) returns number of elements in the object











Join us: https://t.me/jupyter_python

0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (49) AI (34) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (173) C (77) C# (12) C++ (82) Course (67) Coursera (226) Cybersecurity (24) data management (11) Data Science (128) Data Strucures (8) Deep Learning (20) Django (14) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Google (34) Hadoop (3) HTML&CSS (47) IBM (25) IoT (1) IS (25) Java (93) Leet Code (4) Machine Learning (59) Meta (22) MICHIGAN (5) microsoft (4) Nvidia (3) Pandas (4) PHP (20) Projects (29) Python (929) Python Coding Challenge (351) Python Quiz (21) Python Tips (2) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (3) Software (17) SQL (42) UX Research (1) web application (8) Web development (2) web scraping (2)

Followers

Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses