Bạn có thể đăng nhập python không?

Một trong những hàm được sử dụng nhiều nhất trong ngôn ngữ lập trình Python là câu lệnh

import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
0; . Về chức năng, không có bất cứ thứ gì đến gần. Nhưng nó không nên được sử dụng cho tất cả các trường hợp như khi bạn gỡ lỗi — đặc biệt nếu bạn đang làm việc trên một chương trình phức tạp

Bạn có thể bỏ qua việc sử dụng các câu lệnh

import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
0 trong một chương trình đơn giản, nhưng cá nhân tôi không khuyên bạn nên làm như vậy. Bạn nên tập thói quen sử dụng nhật ký để gỡ lỗi mã của mình. Ghi nhật ký là một trong những công cụ hữu ích nhất trong hộp công cụ của lập trình viên. Nó được sử dụng như một công cụ hỗ trợ để hiểu rõ hơn về quy trình của chương trình và xác định các tình huống có thể chưa được xem xét trong khi chương trình đang được phát triển

Python cung cấp cho chúng tôi một mô-đun ghi nhật ký tích hợp có tên là

import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
1. Trong bài viết này, chúng tôi sẽ đề cập đến các khái niệm quan trọng cho phép bạn bắt đầu thêm
import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
1 vào ứng dụng của mình

Table of contents: 
--> A simple introduction to Python's logging module
--> Configuring the logger
--> Creating your own logger object
--> Understanding when to use logging
Giới thiệu đơn giản về mô-đun ghi nhật ký của Python

Nhật ký là tài liệu được tạo tự động, được đánh dấu thời gian về các sự kiện có liên quan đến chương trình. Để tạo ra thông tin như vậy, bộ ghi nhật ký liên tục theo dõi luồng ứng dụng và lưu trữ thông tin cần thiết [i. e. ai đã truy cập chương trình và vào thời điểm nào]

Trong Python, bạn có thể sử dụng mô-đun

import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
1 để tạo nhật ký. Đó là một Python tích hợp sẵn phổ biến được hầu hết các thư viện bên thứ ba sử dụng, có nghĩa là bạn có thể tích hợp thông điệp tường trình của mình với thông điệp tường trình của các thư viện bạn đang sử dụng, nhưng đây không phải là điều thú vị duy nhất về nó

Một tính năng thú vị khác của mô-đun

import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
1 là tập hợp các chức năng mà nó cung cấp để làm cho quá trình ghi nhật ký trở nên đơn giản. Mỗi chức năng ghi nhật ký được đặt tên theo mức độ nghiêm trọng của sự kiện — điều này cho phép ghi lại các sự kiện khẩn cấp nhất trong chương trình của bạn

Các cấp độ được xác định, theo thứ tự mức độ nghiêm trọng tăng dần, như sau

  • GỠ LỖI. Được sử dụng để ghi lại các chi tiết cấp thấp liên quan đến mã nguồn, ví dụ, thông báo cho các nhà phát triển rằng một chức năng đã được gọi hoặc giá trị của một đối tượng được lưu trữ trong một biến
  • THÔNG TIN. Được sử dụng cho mục đích thông tin chung liên quan đến những thứ xảy ra trong chương trình, chẳng hạn như tệp đang được đọc hoặc email đang được gửi
  • CẢNH BÁO. Được sử dụng như một cảnh báo để thông báo cho bạn biết rằng chưa có lỗi nhưng có thể có lỗi trong tương lai
  • LỖI. Được sử dụng cho các lỗi có thể ngăn ngừa được
  • PHÊ BÌNH. Dùng cho các lỗi khiến hệ thống bị lỗi hoặc không thể khôi phục

Nói cách khác, không phải tất cả các thông điệp tường trình đều được tạo như nhau

Hãy xem bộ ghi mặc định đi kèm với mô-đun

import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
1

import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message

Bạn có thể nhận thấy hai điều

  1. Các hàm
    import logging >>> logging.debug["debug message"]
    >>> logging.info["info message"]
    >>> logging.warning["warning message"]
    WARNING:root:This is a warning message
    >>> logging.error["error message"]
    ERROR:root:error message
    >>> logging.critical["critical message"]
    CRITICAL:root:critical message
    6 và
    import logging >>> logging.debug["debug message"]
    >>> logging.info["info message"]
    >>> logging.warning["warning message"]
    WARNING:root:This is a warning message
    >>> logging.error["error message"]
    ERROR:root:error message
    >>> logging.critical["critical message"]
    CRITICAL:root:critical message
    7 không được ghi lại. Điều này là do cấu hình mặc định chỉ ghi nhật ký các thông báo có mức độ nghiêm trọng từ
    import logging >>> logging.debug["debug message"]
    >>> logging.info["info message"]
    >>> logging.warning["warning message"]
    WARNING:root:This is a warning message
    >>> logging.error["error message"]
    ERROR:root:error message
    >>> logging.critical["critical message"]
    CRITICAL:root:critical message
    8 trở lên
  2. Định dạng đầu ra của các tin nhắn đã ghi là
    import logging >>> logging.debug["debug message"]
    >>> logging.info["info message"]
    >>> logging.warning["warning message"]
    WARNING:root:This is a warning message
    >>> logging.error["error message"]
    ERROR:root:error message
    >>> logging.critical["critical message"]
    CRITICAL:root:critical message
    9

Chúng tôi có thể định cấu hình thông báo nhật ký của mình như bạn sẽ thấy trong phần tiếp theo

Định cấu hình bộ ghi

Trong phần trên, chúng tôi đã đề cập đến mô-đun ghi nhật ký với các cài đặt mặc định nhưng đôi khi các giá trị mặc định không như chúng tôi muốn. Trong những tình huống như vậy, chúng tôi có thể thiết lập trình ghi nhật ký của mình bằng cách định cấu hình nó với

import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
10

Các tham số được sử dụng phổ biến nhất của

import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
10 bao gồm

  • import logging >>> logging.debug["debug message"]
    >>> logging.info["info message"]
    >>> logging.warning["warning message"]
    WARNING:root:This is a warning message
    >>> logging.error["error message"]
    ERROR:root:error message
    >>> logging.critical["critical message"]
    CRITICAL:root:critical message
    12— Chỉ định một
    import logging >>> logging.debug["debug message"]
    >>> logging.info["info message"]
    >>> logging.warning["warning message"]
    WARNING:root:This is a warning message
    >>> logging.error["error message"]
    ERROR:root:error message
    >>> logging.critical["critical message"]
    CRITICAL:root:critical message
    13 được tạo bằng cách sử dụng
    import logging >>> logging.debug["debug message"]
    >>> logging.info["info message"]
    >>> logging.warning["warning message"]
    WARNING:root:This is a warning message
    >>> logging.error["error message"]
    ERROR:root:error message
    >>> logging.critical["critical message"]
    CRITICAL:root:critical message
    12 đã chỉ định thay vì một
    import logging >>> logging.debug["debug message"]
    >>> logging.info["info message"]
    >>> logging.warning["warning message"]
    WARNING:root:This is a warning message
    >>> logging.error["error message"]
    ERROR:root:error message
    >>> logging.critical["critical message"]
    CRITICAL:root:critical message
    15;
  • import logging >>> logging.debug["debug message"]
    >>> logging.info["info message"]
    >>> logging.warning["warning message"]
    WARNING:root:This is a warning message
    >>> logging.error["error message"]
    ERROR:root:error message
    >>> logging.critical["critical message"]
    CRITICAL:root:critical message
    17 — Nếu một
    import logging >>> logging.debug["debug message"]
    >>> logging.info["info message"]
    >>> logging.warning["warning message"]
    WARNING:root:This is a warning message
    >>> logging.error["error message"]
    ERROR:root:error message
    >>> logging.critical["critical message"]
    CRITICAL:root:critical message
    12 được chỉ định thì tệp sẽ được mở trong
    import logging >>> logging.debug["debug message"]
    >>> logging.info["info message"]
    >>> logging.warning["warning message"]
    WARNING:root:This is a warning message
    >>> logging.error["error message"]
    ERROR:root:error message
    >>> logging.critical["critical message"]
    CRITICAL:root:critical message
    17 đã cho. Chế độ mặc định là 'a'. tìm hiểu thêm về các chế độ khác nhau
  • Table of contents: 
    --> A simple introduction to Python's logging module
    --> Configuring the logger
    --> Creating your own logger object
    --> Understanding when to use logging
    10 — Chuỗi định dạng đã chỉ định sẽ được sử dụng cho trình xử lý;
  • Table of contents: 
    --> A simple introduction to Python's logging module
    --> Configuring the logger
    --> Creating your own logger object
    --> Understanding when to use logging
    12 — Mức độ nghiêm trọng được chỉ định mà trình ghi nhật ký gốc phải được đặt thành

Hãy khám phá thêm các thông số này

Chúng tôi có thể đặt mức độ nghiêm trọng của thông điệp tường trình của mình bằng cách sử dụng tham số

Table of contents: 
--> A simple introduction to Python's logging module
--> Configuring the logger
--> Creating your own logger object
--> Understanding when to use logging
12

import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
1

Nếu chúng tôi muốn gửi thông điệp tường trình của mình tới một tệp thay vì bảng điều khiển, chúng tôi phải chuyển đối số

import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
12 tới
import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
10 của mình và cung cấp tên mà chúng tôi muốn lưu tệp dưới

Ghi chú.

Table of contents: 
--> A simple introduction to Python's logging module
--> Configuring the logger
--> Creating your own logger object
--> Understanding when to use logging
16 chỉ có thể được gọi nếu bộ ghi gốc chưa được định cấu hình — nó chỉ có thể được gọi một lần. Vì vậy, hãy tưởng tượng một vài đoạn mã tiếp theo đang cập nhật tập lệnh ở trên thay vì mở rộng nó

Table of contents: 
--> A simple introduction to Python's logging module
--> Configuring the logger
--> Creating your own logger object
--> Understanding when to use logging
1

Việc thực hiện cập nhật này cho mã của chúng tôi giờ đây sẽ nối tất cả các thông báo nhật ký tiếp theo vào tệp có tên

Table of contents: 
--> A simple introduction to Python's logging module
--> Configuring the logger
--> Creating your own logger object
--> Understanding when to use logging
17 trong thư mục làm việc hiện tại của bạn — điều này có nghĩa là nếu tệp đã tồn tại thì trình ghi nhật ký sẽ chỉ cần thêm các nhật ký mới của bạn vào cuối tệp

Bạn có thể thay đổi hành vi này bằng cách đặt

import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
17. Theo mặc định, tham số
import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
17 được đặt thành
import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
30, có nghĩa là tệp “được mở để ghi, nối thêm vào cuối tệp nếu nó tồn tại” [Nguồn. Tài liệu ghi nhật ký]. Hãy thay đổi
import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
17 thành
import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
32. “mở để viết, trước tiên hãy cắt bớt tệp. ”

import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
3

Mỗi khi chương trình được chạy, tệp nhật ký sẽ được viết lại do thay đổi chúng tôi đã thực hiện đối với

import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
17

Hiện tại, thông điệp bản ghi đang được lưu trữ là từ định dạng mặc định —

Table of contents: 
--> A simple introduction to Python's logging module
--> Configuring the logger
--> Creating your own logger object
--> Understanding when to use logging
11. Chúng tôi có thể thay đổi điều này bằng cách đặt tham số
Table of contents: 
--> A simple introduction to Python's logging module
--> Configuring the logger
--> Creating your own logger object
--> Understanding when to use logging
10 trong cấu hình mặc định của chúng tôi

import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
0

Thông báo sẽ giống như thế này nhưng sẽ được ghi vào tệp có tên

import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
36 thay vì bảng điều khiển

Mô-đun

import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
1 cũng cung cấp một số yếu tố tốc ký có thể dễ dàng thêm vào định dạng đầu ra. Ví dụ: chúng ta có thể sử dụng
import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
38 để xuất thời gian mà con người có thể đọc được khi
import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
39 được tạo

import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
5

Thông điệp nhật ký mới của chúng tôi trong tệp

Table of contents: 
--> A simple introduction to Python's logging module
--> Configuring the logger
--> Creating your own logger object
--> Understanding when to use logging
17 sẽ như sau

import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
7Tạo đối tượng logger của riêng bạn

Cho đến thời điểm này, chúng tôi đã làm việc với trình ghi nhật ký mặc định có tên

import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
01. Tài liệu
import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
1 khuyên chúng ta nên tạo đối tượng logger của lớp
import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
03 — điều này thậm chí còn quan trọng hơn khi có nhiều mô-đun trong ứng dụng của bạn

Trình ghi nhật ký KHÔNG BAO GIỜ được khởi tạo trực tiếp mà phải luôn thông qua hàm cấp mô-đun

import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
04. Nhiều cuộc gọi đến
import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
05 có cùng tên sẽ luôn trả về một tham chiếu đến cùng một đối tượng Logger.
— [Nguồn. Tài liệu đối tượng Logger].

Đây là một số mã từ dự án phát hiện gian lận của tôi

Tên của tệp python là

import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
06. do đó, chúng tôi đã khởi tạo một trình ghi nhật ký tùy chỉnh trong biến
import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
07 có tên là
import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
08 [xem dòng 11]

“Chúng tôi khuyên chúng ta nên sử dụng trình ghi nhật ký cấp mô-đun bằng cách chuyển

import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
09 làm tham số tên cho
import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
50 để tạo đối tượng trình ghi nhật ký vì chính tên của trình ghi nhật ký sẽ cho chúng tôi biết các sự kiện đang được ghi lại từ đâu.
import logging >>> logging.debug["debug message"]
>>> logging.info["info message"]
>>> logging.warning["warning message"]
WARNING:root:This is a warning message
>>> logging.error["error message"]
ERROR:root:error message
>>> logging.critical["critical message"]
CRITICAL:root:critical message
09 là một biến tích hợp đặc biệt trong Python dùng để đánh giá tên của mô-đun hiện tại. ”
— [Nguồn. Tài liệu đối tượng Logger].

Hiểu khi nào nên sử dụng ghi nhật ký

Nếu bạn giống tôi, có lẽ bạn vẫn đang đọc và tự hỏi làm thế nào bạn nên biết một thông điệp tường trình nên được cung cấp những gì

Tài liệu ghi nhật ký cung cấp cho chúng tôi hướng dẫn hữu ích

Khi nào sử dụng ghi nhật ký; . Ghi nhật ký HOWTO]

Còn rất nhiều điều chúng tôi có thể đề cập về việc ghi nhật ký, nhưng điều này là đủ để bạn bắt đầu. Áp dụng càng nhiều điều chúng tôi đã đề cập trong bài viết này vào một dự án cá nhân để củng cố kiến ​​thức. Đừng ngại tham khảo tài liệu khi bạn cần

Cảm ơn vì đã đọc

Kết nối với tôi.
LinkedIn
Twitter
Instagram

Nếu bạn thích đọc những câu chuyện như thế này và muốn hỗ trợ bài viết của tôi, hãy cân nhắc trở thành thành viên Medium. Với cam kết $5 một tháng, bạn mở khóa quyền truy cập không giới hạn vào các câu chuyện trên Phương tiện. Nếu bạn sử dụng liên kết đăng ký của tôi, tôi sẽ nhận được một khoản hoa hồng nhỏ

Python có chức năng ghi nhật ký không?

Python cung cấp nhiều hàm logarit có sẵn trong mô-đun “toán học” cho phép chúng tôi tính toán nhật ký bằng một dòng duy nhất. Có 4 biến thể của hàm logarit, tất cả đều được thảo luận trong bài viết này. 1. nhật ký [a, [Cơ sở]]. Hàm này được sử dụng để tính logarit tự nhiên [Cơ số e] của một.

Nhật ký có giống như ln trong Python không?

log là ln , trong khi np. log10 là nhật ký cơ sở 10 tiêu chuẩn của bạn.

Có chức năng ln trong Python không?

Python không có hàm ln , hãy sử dụng log cho logarit tự nhiên.

Chủ Đề