Artcafe Easy Programming Learning - Python programming part 2

ArtCafe
2

Usage of Variable in Python

Variable are very important topic in any computer programming language. Today, Artcafe, we provide a good knowledge about variable in the Python programming language. First, let’s see what these variables are. For that, let’s take an example. If we think, we are going to build an employee management software system for a company. So we have to store the many details of the employees. For examples employee id, employee name, employee age, employee address etc. So we need to allocate some space from the computer memory for that. So in this matter, we need the variables. Simply a variable is a symbolic name for this physical location of the computer memory. This memory location contains values, like numbers, text or more complicated types.

Every variable should be declared before it can be used. Declaring variable means, we are binding the variable to a specific variable data type we want. In python, declaration is not required. If you need of a variable, you can name it and using it as a variable. The name that you assigned for the variable, called Identifier.

Example >>> userid=10

In the above of the line we assign the values 10 to the variable called userid. When we name a variable, there are some rules for a valid identifier.
  • First character of the identifier can be the underscore “_” or a letter capital of lower case.
  • The start character can be anything which is permitted as a start character + digits.
  • The keywords of python are not allowed to use as an identifier name.

Python keywords:

and, as, assert, break, class, continue, def, del, elif, else, except, exec, finally, for, from, global, if, import, in, is, lambda, not, or, pass, print, raise, return, try, while, with, yield

 Okay, let’s try to store your name and age as variables in the memory and use that variables in python. Open your python shell and type your name instead “artcafe” and your age instead 25 like below screenshot. In here there are two incident are happening inside the memory. First one, there will be a space allocation inside the memory to store your name and age. As well as the values are you initiate to the variable are stored in that two spaces inside the memory.

We can use that declared variables in anywhere inside the python program. For example, if we want to print that variables in the shell, we can write below.

 I sure, you will have a problem about the use “ “ only for name variable . There is a reason for that. Because, there are many variable types. In name variable, we simply store a collection of a characters. (String variable) age variable stores a numeric values. Simply, if we use characters, we should initiates the value inside the “ “. But if we initiates numeric values, we don’t need to use “”. By the type of the variable, the space that allocated for a variable is different. 

I will explain the types of variables, more in the next lesson of artcafe Python programming lesson series. If you have any problem or error when coding python or executing commands please write them on a comment box. I will help you to resolve that problems. As well as if you have any suggestions or complain please feel free to comment. See you in next python programming lesson.Thank you.

Post a Comment

2Comments

  1. PNY Trainings is a pioneer Digital Marketing Institute offering Digital Marketing Courses in Lahore.

    ReplyDelete
  2. Digital marketing course and other courses can be helpful in setting a new career paths and also promoting your own business.

    ReplyDelete
Post a Comment