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

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.

主站蜘蛛池模板: 忻州市| 双桥区| 沧源| 乐平市| 远安县| 于田县| 红河县| 龙里县| 莱阳市| 鄄城县| 望都县| 新河县| 山西省| 海南省| 吉安县| 岢岚县| 林芝县| 万州区| 综艺| 青岛市| 彭州市| 江源县| 金乡县| 略阳县| 桃江县| 合阳县| 海安县| 玉环县| 呼玛县| 沙坪坝区| 同心县| 临清市| 醴陵市| 澄江县| 富平县| 蒙自县| 日喀则市| 镶黄旗| 松江区| 扬州市| 神池县|