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

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.
主站蜘蛛池模板: 逊克县| 大庆市| 四子王旗| 若尔盖县| 安平县| 株洲市| 霍州市| 大厂| 腾冲县| 阿拉善盟| 汝阳县| 武强县| 厦门市| 丰宁| 孟州市| 平乡县| 洛宁县| 澳门| 元氏县| 嘉荫县| 湘潭县| 都匀市| 博客| 淮南市| 新宁县| 元朗区| 容城县| 苏州市| 拉孜县| 吴堡县| 方正县| 伊春市| 连城县| 德兴市| 泌阳县| 内乡县| 洱源县| 稷山县| 藁城市| 融水| 崇左市|