python保留两位小数

img

img


请问这个为什么报错啊,。?!……得劲儿竞技等级我就睡觉
😪时间段

{:.2f} 要用引号括起来

  • 这个问题的回答你可以参考下: https://ask.csdn.net/questions/764717
  • 我还给你找了一篇非常好的博客,你可以看看是否有帮助,链接:python解决亲密数问题,超级简单。
  • 除此之外, 这篇博客: Python经典高频率面试问答题汇总!内附答案!中的 48、 什么是断言?应用场景是什么? 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • assert 是的作用?断言
    条件成立(布尔值为True)则继续往下,否则跑出异常,一般用于:满足某个条件之后,才能执行,否则应该跑出异常。
    
    写API的时候,继承GenericAPIView
    
    class GenericAPIView(views.APIView):
                        """
                        Base class for all other generic views.
                        """
                        # You'll need to either set these attributes,
                        # or override `get_queryset()`/`get_serializer_class()`.
                        # If you are overriding a view method, it is important that you call
                        # `get_queryset()` instead of accessing the `queryset` property directly,
                        # as `queryset` will get evaluated only once, and those results are cached
                        # for all subsequent requests.
                        queryset = None
                        serializer_class = None
    
                        # If you want to use object lookups other than pk, set 'lookup_field'.
                        # For more complex lookup requirements override `get_object()`.
                        lookup_field = 'pk'
                        lookup_url_kwarg = None
    
                        # The filter backend classes to use for queryset filtering
                        filter_backends = api_settings.DEFAULT_FILTER_BACKENDS
    
                        # The style to use for queryset pagination.
                        pagination_class = api_settings.DEFAULT_PAGINATION_CLASS
    
                        def get_queryset(self):
    
                            assert self.queryset is not None, (
                                "'%s' should either include a `queryset` attribute, "
                                "or override the `get_queryset()` method."
                                % self.__class__.__name__
                            )
    
                            queryset = self.queryset
                            if isinstance(queryset, QuerySet):
                                # Ensure queryset is re-evaluated on each request.
                                queryset = queryset.all()
                            return queryset
    
  • 您还可以看一下 黄勇老师的Python从入门到实战 基础入门视频教程(讲解超细致)课程中的 子类不能继承父类的私有···小节, 巩固相关知识点