Strings Methods.


Strings Methods:

In this topic, you were introduced to methodsMethods are like some of the functions you have already seen:
len("this")
type(12)
print("Hello world")


These three above are functions - notice they use parentheses and accept one or more arguments. Functions will be studied in much more detail later.
A method in Python behaves similarly to a function. Methods actually are functions that are called using dot notation. For example, lower() is a string method that can be used like this, on a string called "sample string": sample_string.lower().
Methods are specific to the data type for a particular variable. So there are some built-in methods that are available for all strings, different methods that are available for all integers, etc.
Below is an image that shows some methods that are possible with any string.
Each of these methods accepts the string itself as the first argument of the method. However, they also could receive additional arguments, that are passed inside the parentheses. Let's look at the output for a few examples.

One important string method: Format()

We will be using the format() string method a good bit in our future work in Python, and you will find it very valuable in your coding, especially with your print statements.
We can best illustrate how to use format() by looking at some examples:

Some Functions:



Post a Comment

0 Comments