Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 我可以用python制作一个变量数组吗?_Arrays_Variables_Python 2.7 - Fatal编程技术网

Arrays 我可以用python制作一个变量数组吗?

Arrays 我可以用python制作一个变量数组吗?,arrays,variables,python-2.7,Arrays,Variables,Python 2.7,我正在使用Python2.7和Gedit。 我写了一个简单的程序来计算我的收入。 现在我认为把变量放在数组中会很有用,这可能吗 # this is a test program # my work week that I wish could hold the values of the following variables workweek = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday',

我正在使用Python2.7和Gedit。 我写了一个简单的程序来计算我的收入。 现在我认为把变量放在数组中会很有用,这可能吗

# this is a test program

# my work week that I wish could hold the values of the following variables
workweek = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday',        'saturday']

# The variables I would like to place in an array
sunday = 0
monday = 0
tuesday = 0
wednesday = 9
thursday = 9
friday = 9
saturday = 9

print sunday + monday + tuesday + wednesday + thursday + friday + saturday

# my wage for sunday through thursday
weekdaywage = 4.25

# my wage for friday and saturday
weekendwage = 3.25

# this is my wages on thursday...
print thursday * weekdaywage

# this is coming out as an error? What can I do as a workaround
# I did a googlesearch
# All I need is a link to learning material if you don't have time to explain
print workweek * weekdaywage

我想你需要一本字典

workweek = {
    'sunday': 0
    'monday': 0
    'tuesday': 0
    'wednesday': 9
    'thursday': 9
    'friday': 9
    'saturday': 9   
}
可以使用以下命令检索变量的值:

workweek['monday']
这确实会打乱订单,如果您希望维持当天的订单,请使用OrderedICT

from collections import OrderedDict
p = OrderedDict([('monday', 1), ('tuesday', 0)])