Bifalgorithm post

So to declare a variable, we start by typing a name for that variable, let's say age. Then we add an equal sign and then we type a value, let's say 20. So with this, we're storing the number 20 somewhere in our computer's memory and we're attaching this age as a label for that memory location. So now we can read the value at this memory location and print it on the terminal. So instead of printing Hello World, we want to print the value of the age variable. So I'm going to delete what we have inside parenthesis and type age. Note that I'm not adding quotes. Because if I run this program, we'll see the text age on the terminal. We don't want that. We want the value of the age variable. So let's remove the quotes and print the value of the age variable. Now here on the toolbar, you can click on this play icon to run your program, or you can use the shortcut that I showed you in the last video. Now you can see the value of the age variable. Now we can also change the value of a variable. For example, on line 2, we can set age to 30. Now when we run our program, we see 30. So as you can see, our program gets executed from top to bottom. So this is how we can declare and use a variable. Now let's look at a few more examples. So I'm going to declare another variable called price and set it to 19.95. So in Python, we can use numbers with a decimal point or whole numbers. We can also declare a variable and assign it a string value. So let's say first underline name. So if you want to use multiple words in the name of a variable, we should separate them using an underscore. This makes our code more readable. See what would happen if I didn't use this underline. This is not easily readable. So we always separate multiple words by an underscore. Now we set this to a string. So we can use single quotes or double quotes. Let's say, "osh. You also have a special type of value called a Boolean value, which can be true or false. That is like yes or no in English. Let me show you. So I'm going to declare another variable called is online and set it to true. We could also set it to false. What we have here is called a Boolean value. Now, note that Python is a case sensitive language, so it's sensitive to lowercase and uppercase letters. In this case, if I use a lowercase f, you can see an error over here, because this is not recognized in Python. So false with a capital F is a special keyword in Python that represents the Boolean false value. So this is how we can declare and use variables in Python.

So to declare a variable, we start by typing a name for that variable, let's say age. Then we add an equal sign and then we type a value, let's say 20. So with…

Ideas in this flowchart

  • Variable Declaration in Python
  • Declaring a Variable
  • Name the Variable
  • Assign a Value
  • Storing in Memory
  • Printing Variable Value
  • Print on Terminal
  • Remove Quotes
  • Run Program
  • Change Variable Value
  • Set New Value
  • Program Execution Order
  • Variable Types
  • Numeric Values
  • String Values
  • Boolean Values
  • Case Sensitivity in Python
Feed/

So to declare a variable, we start by typing a name for that variable, let's say age. Then we add an equal sign and then we type a value, let's say 20. So with this, we're storing the number 20 somewhere in our computer's memory and we're attaching this age as a label for that memory location. So now we can read the value at this memory location and print it on the terminal. So instead of printing Hello World, we want to print the value of the age variable. So I'm going to delete what we have inside parenthesis and type age. Note that I'm not adding quotes. Because if I run this program, we'll see the text age on the terminal. We don't want that. We want the value of the age variable. So let's remove the quotes and print the value of the age variable. Now here on the toolbar, you can click on this play icon to run your program, or you can use the shortcut that I showed you in the last video. Now you can see the value of the age variable. Now we can also change the value of a variable. For example, on line 2, we can set age to 30. Now when we run our program, we see 30. So as you can see, our program gets executed from top to bottom. So this is how we can declare and use a variable. Now let's look at a few more examples. So I'm going to declare another variable called price and set it to 19.95. So in Python, we can use numbers with a decimal point or whole numbers. We can also declare a variable and assign it a string value. So let's say first underline name. So if you want to use multiple words in the name of a variable, we should separate them using an underscore. This makes our code more readable. See what would happen if I didn't use this underline. This is not easily readable. So we always separate multiple words by an underscore. Now we set this to a string. So we can use single quotes or double quotes. Let's say, "osh. You also have a special type of value called a Boolean value, which can be true or false. That is like yes or no in English. Let me show you. So I'm going to declare another variable called is online and set it to true. We could also set it to false. What we have here is called a Boolean value. Now, note that Python is a case sensitive language, so it's sensitive to lowercase and uppercase letters. In this case, if I use a lowercase f, you can see an error over here, because this is not recognized in Python. So false with a capital F is a special keyword in Python that represents the Boolean false value. So this is how we can declare and use variables in Python.

"So to declare a variable, we start by typing a name for that variable, let's say age."

👍
0
0 comments0 shares

Sign in to view and post comments.