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

Data types and variables in Python

In Python, variables are used to store a result or a value in the computer's memory during the execution of a program. Variables enable easy access to a specific location on the computer's memory and enables writing user-readable code.

For example, let's consider a scenario where a person wants a new ID card from an office or a university. The person would be asked to fill out an application form with relevant information, including their name, department, and emergency contact information. The form would have the requisite fields. This would enable the office manager to refer to the form while creating a new ID card.

Similarly, variables simplify code development by providing means to store information in the computer's memory. It would be very difficult to write code if one had to write code keeping the storage memory map in mind. For example, it is easier to use the variable called name rather than a specific memory address like 0x3745092.

There are different kinds of data types in Python. Let's review the different data types:

  • In general, names, street addresses, and so on are a combination of alphanumeric characters. In Python, they are stored as strings. Strings in Python are represented and stored in variables as follows:
       >>>name = 'John Smith' 
>>>address = '123 Main Street'
  • Numbers in Python could be stored as follows:
       >>>age = 29 
>>>employee_id = 123456
>>>height = 179.5
>>>zip_code = 94560
  • Python also enables storing boolean variables. For example, a person's organ donor status can be either as True or False:
       >>>organ_donor = True
  • It is possible to assign values to multiple variables at the same time:
       >>>a = c= 1 
>>>b = a
  • A variable may be deleted as follows:
       >>>del(a)

There are other data types in Python, including lists, tuples, and dictionaries. We will discuss this in detail in the next chapter.

主站蜘蛛池模板: 元江| 同仁县| 富顺县| 张家川| 阿拉善盟| 九台市| 浦城县| 农安县| 黑山县| 大悟县| 奉化市| 柳河县| 沁源县| 黄陵县| 漳州市| 安国市| 山阳县| 玛多县| 嘉峪关市| 楚雄市| 西乡县| 包头市| 盐城市| 新宁县| 五寨县| 清远市| 新闻| 会昌县| 嘉黎县| 安徽省| 砚山县| 崇礼县| 太白县| 青岛市| 屯昌县| 论坛| 普陀区| 石棉县| 浮山县| 漠河县| 即墨市|