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

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.

主站蜘蛛池模板: 嵩明县| 德清县| 合作市| 烟台市| 静安区| 绥德县| 旺苍县| 灵宝市| 凤凰县| 偏关县| 庆阳市| 武威市| 许昌县| 综艺| 元谋县| 阳谷县| 霸州市| 福贡县| 夹江县| 稻城县| 平谷区| 兰考县| 合川市| 通渭县| 淮安市| 宁陵县| 开阳县| 陇南市| 长武县| 隆德县| 昌黎县| 新沂市| 扎鲁特旗| 千阳县| 小金县| 册亨县| 江永县| 原阳县| 广灵县| 蒲江县| 安溪县|