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

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.

主站蜘蛛池模板: 昌宁县| 兰西县| 磴口县| 上饶县| 乌兰察布市| 依安县| 南涧| 梧州市| 深泽县| 岑巩县| 滨州市| 津南区| 古丈县| 原平市| 新野县| 左贡县| 宝清县| 常熟市| 天全县| 射阳县| 万荣县| 石柱| 绍兴县| 驻马店市| 称多县| 望谟县| 邯郸市| 铅山县| 遂川县| 越西县| 贡山| 磴口县| 闸北区| 诏安县| 连平县| 遵义县| 南平市| 闵行区| 桃园县| 台湾省| 吉林省|