返回声明的目的是什么(**)

时间:2018-05-15 08:01:18

标签: python django python-3.x python-2.7 keyword-argument

我正在阅读Django serialization

class SnippetSerializer(serializers.Serializer):
    id = serializers.IntegerField(read_only=True)
    title = serializers.CharField(required=False, allow_blank=True, max_length=100)
    code = serializers.CharField(style={'base_template': 'textarea.html'})
    linenos = serializers.BooleanField(required=False)
    language = serializers.ChoiceField(choices=LANGUAGE_CHOICES, default='python')
    style = serializers.ChoiceField(choices=STYLE_CHOICES, default='friendly')

    def create(self, validated_data):
        """
        Create and return a new `Snippet` instance, given the validated data.
        """
        return Snippet.objects.create(**validated_data)

为什么我们需要**返回声明?

1 个答案:

答案 0 :(得分:1)

如果要将关键字参数用作参数,则需要使用**

指定