变量类型Python

时间:2014-01-24 21:53:26

标签: python variables

x = 4
name = "Josh"
y = 3.2
guess = True
stuff = ["guitar", "bed"]
days = {"Monday":"favourite", "Friday": "least favourite"}
jay = (3, 9)

我正在学习Python,目前正在学习各种类型的变量。当前练习要求我选择定义哪种类型的变量。选项包括:Array,Boolean,decimal,dictionary,float,integer,list,string,tuple。有人可以查看我的答案并告诉我你是什么

  • x是一个字符串
  • name是一个字符串
  • y是十进制/浮点数
  • guess是一个布尔
  • stuff是一个列表
  • days是一本字典
  • jay是一个元组

2 个答案:

答案 0 :(得分:5)

尝试一下......

>>> y = 3.2
>>> type(y)
<type 'float'>
>>>

type()功能可以准确地告诉您所要求的内容。

以下是list and description of the built in types

答案 1 :(得分:1)

x = 4  # this is an int (an integer)
name = "Josh"  # string
y = 3.2  # float (decimal point number)
guess = True  # bool (boolean)
stuff = ["guitar", "bed"]  # list
days = {"Monday":"favourite", "Friday": "least favourite"}  # dictionary (a hashmap, in computational-theory speak)
jay = (3, 9)  # tuple (works like a list, but you can't change the elements)