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

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.
主站蜘蛛池模板: 阜新| 廉江市| 建平县| 襄汾县| 肥城市| 吴旗县| 运城市| 西峡县| 镇巴县| 新营市| 上杭县| 云安县| 读书| 大石桥市| 信丰县| 哈巴河县| 平塘县| 察哈| 军事| 铜山县| 泗洪县| 邹城市| 大渡口区| 衡水市| 清原| 双峰县| 宁安市| 竹北市| 诸城市| 平谷区| 隆子县| 闻喜县| 合阳县| 中牟县| 平潭县| 扶余县| 高台县| 徐州市| 中西区| 登封市| 左云县|