官术网_书友最值得收藏!

Data types

As the name suggests, these are the classifications of the values that we pass on to the variable. A variable can be defined to store a specific type of value that can be declared based upon the data type.

There are multiple data types, but for our initial discussion there are primarily four data types that need to be understood:

  • String: This is a catch-all data type. Any value defined as a string is as simple as saying the value is plain English with characters, alphabets, special characters, and so on. I have referred to it as a catch-all data type because nearly all other data types can be converted to string format keeping the same values intact during conversion to string.

Consider the following example:

number=2

This defines that a variable named number has a value of 2.
Similarly, if we declare:

string_value="2"

This is same as saying that a value of 2 has been now defined as string and stored in a variable named string_value.

  • Integer: This specifies that any value that is a number needs to be defined with this data type. The key thing to note here is that an integer value will contain a whole number and not a decimal value:

Consider an example as follows:

integernumber=2

This defines that a variable named as integernumber has a value of the number 2.
An incorrect assignation here would be something like:

integernumber=2.4

This would give an error in some programming languages as an integer needs to be interpreted as a whole number and not a decimal value.

  • Float: This data type removes the restriction that we saw earlier with integer. It simply means we can have a decimal number and can perform mathematical calculations and storage of decimal values in a float data type.
  • Datetime: This is an extended data type found in a lot of modern scripting languages. This data type ensures that the values that are being stored or retrieved are in date format. This is typically useful if we need to create a program that uses some time or date calculations. As an example, perhaps we need to find out how many syslogs were generated from a router in the last seven days. The last seven days will be stored by this data type.
主站蜘蛛池模板: 新巴尔虎右旗| 阳西县| 富顺县| 兴宁市| 福建省| 通许县| 泗阳县| 盘山县| 黎平县| 瑞安市| 襄城县| 闽侯县| 开平市| 绥江县| 子长县| 怀化市| 鄂尔多斯市| 洛扎县| 玛纳斯县| 长宁区| 册亨县| 慈利县| 河南省| 济南市| 大竹县| 镇安县| 定南县| 如东县| 靖江市| 拉萨市| 湛江市| 甘南县| 资讯 | 靖西县| 平南县| 冕宁县| 常宁市| 虞城县| 阿拉善左旗| 普兰县| 禹州市|