Class: 09 Introduction to Computer Programming --- Complete Course for BSSE and BSCS Students Specially

 





Python Data Types

Python has five standard data types but this programming language does not make use of any keyword to specify a particular data type, rather Python is intelligent enough to understand a given data type automatically.

  • Numbers
  • String
  • List
  • Tuple
  • Dictionary

Here, Number specifies all types of numbers including decimal numbers and string represents a sequence of characters with a length of 1 or more characters. For now, let's proceed with these two data types and skip List, Tuple, and Dictionary, which are advanced data types in Python.


Variables are the names you give to computer memory locations which are used to store values in a computer program.

For example, assume you want to store two values 10 and 20 in your program and at a later stage, you want to use these two values. Let's see how you will do it. Here are the following three simple steps −

  • Create variables with appropriate names.
  • Store your values in those two variables.
  • Retrieve and use the stored values from the variables.

Creating variables

Creating variables is also called declaring variables in C programming. Different programming languages have different ways of creating variables inside a program. For example, C programming has the following simple way of creating variables −

#include <stdio.h>

int main() {
   int a;
   int b;
}

The above program creates two variables to reserve two memory locations with names a and b. We created these variables using int keyword to specify variable data type which means we want to store integer values in these two variables. Similarly, you can create variables to store longfloatchar or any other data type. For example −

/* variable to store long value */
long a;

/* variable to store float value */
float b;

You can create variables of similar type by putting them in a single line but separated by comma as follows −

#include <stdio.h>

int main() {
   int a, b;
}

Listed below are the key points about variables that you need to keep in mind −

  • A variable name can hold a single type of value. For example, if variable a has been defined int type, then it can store only integer.

  • C programming language requires a variable creation, i.e., declaration before its usage in your program. You cannot use a variable name in your program without creating it, though programming language like Python allows you to use a variable name without creating it.

  • You can use a variable name only once inside your program. For example, if a variable a has been defined to store an integer value, then you cannot define a again to store any other type of value.

  • There are programming languages like Python, PHP, Perl, etc., which do not want you to specify data type at the time of creating variables. So you can store integer, float, or long without specifying their data type.

  • You can give any name to a variable like agesexsalaryyear1990 or anything else you like to give, but most of the programming languages allow to use only limited characters in their variables names. For now, we will suggest to use only a....z, A....Z, 0....9 in your variable names and start their names using alphabets only instead of digits.

  • Almost none of the programming languages allow to start their variable names with a digit, so 1990year will not be a valid variable name whereas year1990 or ye1990ar are valid variable names.

Every programming language provides more rules related to variables and you will learn them when you will go in further detail of that programming language.


Research Resources: Internet -- I am not owner of any thing!

Post a Comment

أحدث أقدم