Velofel South Africa (ZA) function to count the number of characters


Velofel ZA Let's take a look. So I'm going to run the program One more time, look, we still get python for beginners. We can also replace a single character, for example we can replace capital p with let's say capital j. Now when we run this program we get jython for beginners. So these are the find and replace methods and one last things I want to show you in this tutorial. There are times that you want to check the existence of a character or sequence of characters in your string. In those situations you use the in operator, so let's say you want to know if this string contains the word python. We can write an expression like this. String python space in space course. So we're checking to see if python is in course variable. And this is an expression that produces a boolean value, and I get true or false, so we refer to this expression as a boolean expression, now if we print this on the terminal, we should get true, and by the way I'm going to delete the second line, we don't need it anymore, so run the program we get true, but if I change this capitol p to a lower case p and run the program we get false because we don't have is exact sequence of characters in our strings. Now note that the difference between the in operator and the find method is that our find method returns the index of character or sequence of characters but the in operator produces a boolean value. Do we have this or not? So that's the difference. Now let's recap all the cool things you learned to do with strings in this tutorial. We can use the len 

Velofel South Africa (ZA) function to count the number of characters in a string, this is the general purpose function built into python, we also have specific functions for strings which we refer to as methods, these include upper for converting a string into uppercase you also have lower and title methods, you learn about the find method which returns the index of a character or sequence of characters, we have the replace method for replacing characters and words in a string and finally you learned about the in operator. So some characters in a string. So, you have learned that in Python programming language you have 2 types of numbers, integers which are whole numbers like 10, they don't have a decimal point, and floating point numbers or floats. Which are numbers with a decimal point. Now in this tutorial you're going to look at the arithmetic operations supported in python language these are the same arithmetic operations that we have in math, we can add numbers, multiply them and so on. So let's look at a few examples, we can print, 10 plus 3, so this is the addition operator, we also have subtraction, we have multiplication, we have two kinds of division, here's one with a forward slash, let's run this program and see what we get. we get a floating point number. But we also have another division operator for getting an integer. So if we add another slash here and run this program we get an integer. We have another operator called modulis (?) which is a percent sign. And this returns the remainder of the division. 

Velofel South Africa So when we run this program we should get 1, there you go. And one last operator we have here is exponent which is the power. So, that is indicated with 2 asterisks and this will return 10 to the power of 3. So let's run this program we get 1000 so these are the arithmetic operators in python programming language. Now for all these operators that you learned we have an augmented assignment operator. That is very useful, let me show you. So let's say we have a variable called x we set it to 10, now we want to increment this by 3, we'll have to write code like this. X we set this to x plus 3. So Python interpreter will add 10 to 3, the result is 13, and then it gets stored into x again. So when we print x we should see 13, there you go. So this is how you can increment a number, right? Now augmented assignment operator is a way to write the same code but in a shorter form. This is how it works. We type x plus equals 3. What we have on line 3 is exactly like what we have on line 2. So this is what we call the augmented assignment operator we have augmented or enhanced the assignment operator. Now in this particular case we are incremented a number using the augmented assignment operator, but we can also subtract or multiply a number by a given value for example, let's delete what we have on line 2, we can type subtract equals 3. So here we subtracted 3 from x. When we run this program we should see 7, there you go. Now let me ask you a question, I'm going to clear all this code here 

Comments