Chuẩn bị phỏng vấn Python

Bạn có phải là Nhà phát triển Python đầy tham vọng không? . Vì vậy, nếu bạn đã sẵn sàng đắm mình trong kho kiến ​​thức và chuẩn bị cho cuộc phỏng vấn với trăn sắp tới, thì bạn đang ở đúng nơi

Chúng tôi đã biên soạn một danh sách đầy đủ các Câu hỏi và Câu trả lời Phỏng vấn Python sẽ hữu ích vào thời điểm cần thiết. Khi bạn đã chuẩn bị sẵn sàng cho các câu hỏi mà chúng tôi đã đề cập trong danh sách của mình, bạn sẽ sẵn sàng đảm nhận nhiều vai trò công việc về python như Nhà phát triển python, Nhà khoa học dữ liệu, Kỹ sư phần mềm, Quản trị viên cơ sở dữ liệu, Người kiểm tra đảm bảo chất lượng, v.v.

Lập trình Python có thể đạt được một số chức năng với một vài dòng mã và hỗ trợ tính toán mạnh mẽ bằng các thư viện mạnh mẽ. Do những yếu tố này, nhu cầu về các chuyên gia có kiến ​​thức lập trình Python ngày càng tăng. Kiểm tra miễn phí để tìm hiểu thêm

Blog này bao gồm các Câu hỏi phỏng vấn Python thường gặp nhất sẽ giúp bạn nhận được những lời mời làm việc tuyệt vời

Các câu hỏi được chia thành nhiều loại, như được liệt kê dưới đây

Câu hỏi phỏng vấn Python dành cho người mới

Phần Câu hỏi phỏng vấn Python dành cho người mới này bao gồm hơn 70 câu hỏi thường được hỏi trong quá trình phỏng vấn. Là một người mới hơn, bạn có thể chưa quen với quá trình phỏng vấn; .  

1. Trăn là gì?

Python was created and first released in 1991 by Guido van Rossum. It is a high-level, general-purpose programming language emphasizing code readability and providing easy-to-use syntax. Several developers and programmers prefer using Python for their programming needs due to its simplicity. After 30 years, Van Rossum stepped down as the leader of the community in 2018.  

Python interpreters are available for many operating systems. CPython, the reference implementation of Python, is open-source software and has a community-based development model, as do nearly all of its variant implementations. The non-profit Python Software Foundation manages Python and CPython

2. Why Python?

Python is a high-level, general-purpose programming language. Python is a programming language that may be used to create desktop GUI apps, websites, and online applications. As a high-level programming language, Python also allows you to concentrate on the application’s essential functionality while handling routine programming duties. The basic grammar limitations of the programming language make it considerably easier to maintain the code base intelligible and the application manageable

3. How to Install Python?

To Install Python, go to Anaconda. org and click on “Download Anaconda”. Here, you can download the latest version of Python. After Python is installed, it is a pretty straightforward process. The next step is to power up an IDE and start coding in Python. If you wish to learn more about the process, check out this Python Tutorial. Check out How to install python

Check out this pictorial representation of python installation

4. Các ứng dụng của Python là gì?

Python is notable for its general-purpose character, which allows it to be used in practically any software development sector. Python may be found in almost every new field. It is the most popular programming language and may be used to create any application

– Web Applications

We can use Python to develop web applications. It contains HTML and XML libraries, JSON libraries, email processing libraries, request libraries, beautiful soup libraries, Feedparser libraries, and other internet protocols. Instagram uses Django, a Python web framework

– Desktop GUI Applications

The Graphical User Interface [GUI] is a user interface that allows for easy interaction with any programme. Python contains the Tk GUI framework for creating user interfaces

– Console-based Application

The command-line or shell is used to execute console-based programmes. These are computer programmes that are used to carry out orders. This type of programme was more common in the previous generation of computers. It is well-known for its REPL, or Read-Eval-Print Loop, which makes it ideal for command-line applications

Python has a number of free libraries and modules that help in the creation of command-line applications. To read and write, the appropriate IO libraries are used. It has capabilities for processing parameters and generating console help text built-in. There are additional advanced libraries that may be used to create standalone console applications

– Software Development

Python is useful for the software development process. It’s a support language that may be used to establish control and management, testing, and other things

  • SCons are used to build control
  • Continuous compilation and testing are automated using Buildbot and Apache Gumps

– Scientific and Numeric

This is the time of artificial intelligence, in which a machine can execute tasks as well as a person can. Python is an excellent programming language for artificial intelligence and machine learning applications. It has a number of scientific and mathematical libraries that make doing difficult computations simple

Putting machine learning algorithms into practice requires a lot of arithmetic. Numpy, Pandas, Scipy, Scikit-learn, and other scientific and numerical Python libraries are available. If you know how to use Python, you’ll be able to import libraries on top of the code. A few prominent machine library frameworks are listed below

  • khoa học viễn tưởng
  • Scikit learn
  • NumPy
  • Pandas
  • Matplotlib

– Business Applications

Standard apps are not the same as business applications. This type of program necessitates a lot of scalability and readability, which Python gives

Oddo is a Python-based all-in-one application that offers a wide range of business applications. The commercial application is built on the Tryton platform, which is provided by Python

– Audio or Video-based Applications

Python is a versatile programming language that may be used to construct multimedia applications. TimPlayer, cplay, and other multimedia programmes written in Python are examples

– 3D CAD Applications

Engineering-related architecture is designed using CAD [Computer-aided design]. It’s used to create a three-dimensional visualization of a system component. Các tính năng sau trong Python có thể được sử dụng để phát triển ứng dụng CAD 3D

  • Fandango [Phổ biến]
  • CAMVOX
  • GótCNC
  • AnyCAD
  • RCAM

– Ứng dụng doanh nghiệp

Python có thể được sử dụng để phát triển ứng dụng để sử dụng trong doanh nghiệp hoặc tổ chức. OpenERP, Tryton, Picalo tất cả các ứng dụng thời gian thực này là ví dụ.  

– Ứng dụng xử lý ảnh

Python có rất nhiều thư viện để làm việc với hình ảnh. Hình ảnh có thể được thay đổi theo thông số kỹ thuật của chúng tôi. OpenCV, Gối và SimpleITK là tất cả các thư viện xử lý hình ảnh có trong python. Trong chủ đề này, chúng tôi đã đề cập đến nhiều loại ứng dụng trong đó Python đóng vai trò quan trọng trong quá trình phát triển của chúng. Chúng ta sẽ nghiên cứu thêm về các nguyên tắc của Python trong hướng dẫn sắp tới

5. Ưu điểm của Python là gì?

Python là một ngôn ngữ lập trình động có mục đích chung là cấp cao và được giải thích. Khung kiến ​​trúc của nó ưu tiên khả năng đọc mã và sử dụng rộng rãi thụt đầu dòng

  • Các mô-đun của bên thứ ba có mặt
  • Một số thư viện hỗ trợ có sẵn [NumPy để tính toán số, Pandas để phân tích dữ liệu, v.v.]
  • Phát triển cộng đồng và mã nguồn mở
  • Thích nghi, đơn giản để đọc, học và viết
  • Cấu trúc dữ liệu khá dễ làm việc
  • ngôn ngữ cấp cao
  • Ngôn ngữ được gõ động [Không cần đề cập đến kiểu dữ liệu dựa trên giá trị được gán, nó sẽ lấy kiểu dữ liệu]
  • Ngôn ngữ lập trình hướng đối tượng
  • Tương tác và vận chuyển
  • Lý tưởng cho các nguyên mẫu vì nó cho phép bạn thêm các tính năng bổ sung với mã tối thiểu
  • Hiệu quả cao
  • Khả năng của Internet vạn vật [IoT]
  • Ngôn ngữ thông dịch di động trên các hệ điều hành
  • Vì nó là một ngôn ngữ được giải thích nên nó thực thi bất kỳ dòng mã nào theo từng dòng và đưa ra lỗi nếu nó tìm thấy thứ gì đó bị thiếu
  • Python miễn phí sử dụng và có một cộng đồng mã nguồn mở lớn
  • Python có rất nhiều hỗ trợ cho các thư viện cung cấp nhiều chức năng để thực hiện bất kỳ tác vụ nào trong tầm tay
  • Một trong những tính năng tốt nhất của Python là tính di động của nó. nó có thể và chạy trên bất kỳ nền tảng nào mà không phải thay đổi các yêu cầu
  • Cung cấp nhiều chức năng với ít dòng mã hơn so với các ngôn ngữ lập trình khác như Java, C++, v.v.

Bẻ khóa cuộc phỏng vấn Python của bạn

Các khóa học Python miễn phí

6. Các tính năng chính của Python là gì?

Python là một trong những ngôn ngữ lập trình phổ biến nhất được sử dụng bởi các nhà khoa học dữ liệu và chuyên gia AIML. Sự phổ biến này là do các tính năng chính sau đây của Python

  • Python rất dễ học do cú pháp rõ ràng và dễ đọc
  • Python rất dễ diễn giải, giúp gỡ lỗi dễ dàng
  • Python là mã nguồn mở và miễn phí
  • Nó có thể được sử dụng trên các ngôn ngữ khác nhau
  • Nó là một ngôn ngữ hướng đối tượng hỗ trợ các khái niệm về lớp
  • Nó có thể dễ dàng tích hợp với các ngôn ngữ khác như C ++, Java, v.v.

7. Bạn có ý nghĩa gì bởi chữ Python?

Một nghĩa đen là một hình thức đơn giản và trực tiếp để thể hiện một giá trị. Chữ phản ánh các tùy chọn kiểu nguyên thủy có sẵn trong ngôn ngữ đó. Số nguyên, số dấu phẩy động, Booleans và chuỗi ký tự là một số dạng phổ biến nhất của chữ. Python hỗ trợ các chữ sau

Chữ trong Python liên quan đến dữ liệu được giữ trong một biến hoặc hằng số. There are several types of literals present in Python

String Literals. Đó là một chuỗi các ký tự được bọc trong một bộ mã. Tùy thuộc vào số lượng trích dẫn được sử dụng, có thể có chuỗi đơn, chuỗi kép hoặc chuỗi ba. Các ký tự đơn được đặt trong dấu ngoặc đơn hoặc kép được gọi là ký tự chữ

chữ số. Đây là những con số không thể thay đổi có thể được chia thành ba loại. số nguyên, số float và số phức

Boolean chữ. Đúng hoặc Sai, biểu thị lần lượt là '1' và '0', có thể được chỉ định cho chúng

chữ đặc biệt. Nó được sử dụng để phân loại các trường chưa được tạo. 'Không' là giá trị được sử dụng để đại diện cho nó

  • Chuỗi ký tự. “hào quang”, ‘12345’
  • chữ int. 0,1,2,-1,-2
  • chữ dài. 89675L
  • chữ nổi. 3. 14
  • Chữ phức tạp. 12j
  • Boolean chữ. Đúng hay sai
  • chữ đặc biệt. Không có
  • chữ Unicode. bạn "xin chào"
  • Liệt kê chữ. [ ], [5, 6, 7]
  • Tuple chữ. [], [9,], [8, 9, 0]
  • chữ chính tả. {}, {'x'. 1}
  • Đặt chữ. {8, 9, 10}

8. Python thuộc loại ngôn ngữ nào?

Python là ngôn ngữ lập trình hướng đối tượng, thông dịch, tương tác. Các lớp, mô-đun, ngoại lệ, gõ động và các kiểu dữ liệu động cấp cao đều có mặt

Python là một ngôn ngữ được giải thích với kiểu gõ động. Bởi vì mã không được chuyển đổi thành dạng nhị phân, nên những ngôn ngữ này đôi khi được gọi là ngôn ngữ "viết kịch bản". Trong khi tôi nói được nhập động, tôi đang đề cập đến thực tế là các loại không cần phải được nêu khi viết mã;

Khả năng đọc cú pháp ngắn gọn, dễ học của Python được ưu tiên, giúp giảm chi phí bảo trì phần mềm. Python cung cấp các mô-đun và gói, cho phép mô-đun hóa chương trình và tái sử dụng mã. Trình thông dịch Python và thư viện tiêu chuẩn toàn diện của nó được tải xuống và phân phối miễn phí ở dạng nguồn hoặc nhị phân cho tất cả các nền tảng chính

9. Python là một ngôn ngữ thông dịch như thế nào?

Trình thông dịch lấy mã của bạn và thực thi [thực hiện] các hành động bạn cung cấp, tạo các biến bạn chỉ định và thực hiện nhiều công việc hậu trường để đảm bảo mã hoạt động trơn tru hoặc cảnh báo bạn về các sự cố

Python không phải là ngôn ngữ được giải thích hoặc biên dịch. Thuộc tính của việc triển khai là liệu nó được giải thích hay biên dịch. Python là một mã byte [một tập hợp các hướng dẫn có thể đọc được bằng trình thông dịch] có thể được diễn giải theo nhiều cách khác nhau

Mã nguồn được lưu trong một. tập tin py

Python tạo một bộ hướng dẫn cho máy ảo từ mã nguồn. Định dạng trung gian này được gọi là “mã byte” và nó được tạo bằng cách biên dịch. mã nguồn py vào. pyc, đó là mã byte. Mã byte này sau đó có thể được giải thích bởi trình thông dịch CPython tiêu chuẩn hoặc JIT của PyPy [trình biên dịch Just in Time]

Python được gọi là ngôn ngữ thông dịch vì nó sử dụng trình thông dịch để chuyển mã bạn viết sang ngôn ngữ mà bộ xử lý máy tính của bạn có thể hiểu được. Sau đó, bạn sẽ tải xuống và sử dụng trình thông dịch Python để có thể tạo mã Python và thực thi nó trên máy tính của riêng bạn khi làm việc trên một dự án

10. pep8 là gì?

PEP 8, thường được gọi là PEP8 hoặc PEP-8, là tài liệu phác thảo các phương pháp hay nhất và khuyến nghị để viết mã Python. Nó được viết vào năm 2001 bởi Guido van Rossum, Barry Warsaw, và Nick Coghlan. Mục tiêu chính của PEP 8 là làm cho mã Python dễ đọc và nhất quán hơn

Đề xuất cải tiến Python [PEP] là từ viết tắt của Đề xuất cải tiến Python và có rất nhiều trong số đó. Đề xuất cải tiến Python [PEP] là tài liệu giải thích các tính năng mới được đề xuất cho Python và chi tiết các yếu tố của Python cho cộng đồng, chẳng hạn như thiết kế và kiểu dáng

11. Không gian tên trong Python là gì?

Trong Python, một không gian tên là một hệ thống gán một tên duy nhất cho mỗi và mọi đối tượng. Một biến hoặc một phương thức có thể được coi là một đối tượng. Python có không gian tên riêng, được lưu giữ dưới dạng từ điển Python. Hãy xem cấu trúc hệ thống tệp-thư mục trong máy tính làm ví dụ. Không cần phải nói rằng một tệp có cùng tên có thể được tìm thấy trong nhiều thư mục. Tuy nhiên, bằng cách cung cấp đường dẫn tuyệt đối của tệp, người ta có thể định tuyến đến tệp nếu muốn

Không gian tên về cơ bản là một kỹ thuật để đảm bảo rằng tất cả các tên trong chương trình là khác biệt và có thể được sử dụng thay thế cho nhau. Bạn có thể đã biết rằng mọi thứ trong Python đều là một đối tượng, bao gồm chuỗi, danh sách, hàm, v.v. Một điều đáng chú ý khác là Python sử dụng từ điển để triển khai các không gian tên. Tồn tại ánh xạ tên với đối tượng, với các tên đóng vai trò là khóa và các đối tượng đóng vai trò là giá trị. The same name can be used by many namespaces, each mapping it to a distinct object. Dưới đây là một vài ví dụ về không gian tên

Không gian tên cục bộ. Không gian tên này lưu trữ tên cục bộ của các chức năng. Không gian tên này được tạo khi một hàm được gọi và chỉ tồn tại cho đến khi hàm trả về

Không gian tên toàn cầu. Tên từ các mô-đun đã nhập khác nhau mà bạn đang sử dụng trong một dự án được lưu trữ trong không gian tên này. Nó được hình thành khi mô-đun được thêm vào dự án và tồn tại cho đến khi hoàn thành tập lệnh

Không gian tên tích hợp. Không gian tên này chứa tên của các hàm và ngoại lệ tích hợp

12. ĐƯỜNG PYTHON là gì?

PYTHONPATH là một biến môi trường cho phép người dùng thêm các thư mục bổ sung vào hệ thống. danh sách thư mục đường dẫn cho Python. Tóm lại, nó là một biến môi trường được đặt trước khi bắt đầu trình thông dịch Python

13. Mô-đun Python là gì?

Mô-đun Python là tập hợp các lệnh và định nghĩa Python trong một tệp. Trong một mô-đun, bạn có thể chỉ định các hàm, lớp và biến. Một mô-đun cũng có thể bao gồm mã thực thi. Khi mã được tổ chức thành các mô-đun, nó sẽ dễ hiểu và dễ sử dụng hơn. Nó cũng tổ chức mã một cách hợp lý

14. Biến cục bộ và biến toàn cục trong Python là gì?

Các biến cục bộ được khai báo bên trong một hàm và có phạm vi chỉ giới hạn trong hàm đó, trong khi các biến toàn cục được định nghĩa bên ngoài bất kỳ hàm nào và có phạm vi toàn cục. Nói cách khác, các biến cục bộ chỉ khả dụng trong hàm mà chúng được tạo, nhưng các biến toàn cục có thể truy cập được trong chương trình và trong mỗi hàm

Biến cục bộ

Biến cục bộ là các biến được tạo trong một hàm và dành riêng cho hàm đó. Ngoài chức năng, nó không thể được truy cập

Biến toàn cầu

Biến toàn cục là các biến được định nghĩa bên ngoài bất kỳ chức năng nào và có sẵn trong toàn bộ chương trình, nghĩa là cả bên trong và bên ngoài của mỗi chức năng

15. Giải thích Flask là gì và lợi ích của nó?

Flask là một khung web mã nguồn mở. Flask là một bộ công cụ, khung và công nghệ để xây dựng các ứng dụng trực tuyến. Trang web, wiki, phần mềm lịch dựa trên web khổng lồ hoặc trang web thương mại được sử dụng để xây dựng ứng dụng web này. Flask là một micro-framework, có nghĩa là nó không phụ thuộc quá nhiều vào các thư viện khác

Những lợi ích

Có một số lý do thuyết phục để sử dụng Flask làm khung ứng dụng web. Giống-

  • Hỗ trợ kiểm tra đơn vị được kết hợp
  • Có một máy chủ phát triển tích hợp cũng như trình gỡ lỗi nhanh
  • Gửi yêu cầu yên tĩnh với cơ sở Unicode
  • Việc sử dụng cookie được cho phép
  • Tạo khuôn mẫu WSGI 1. 0 tương thích jinja2
  • Ngoài ra, bình cung cấp cho bạn toàn quyền kiểm soát tiến độ dự án của bạn
  • Chức năng xử lý yêu cầu HTTP
  • Flask is a lightweight and versatile web framework that can be easily integrated with a few extensions
  • Bạn có thể sử dụng thiết bị yêu thích của mình để kết nối. API chính cho ORM Basic được thiết kế và tổ chức tốt
  • cực kỳ thích nghi
  • Về mặt sản xuất, bình rất dễ sử dụng

16. Django có tốt hơn Flask không?

Django phổ biến hơn vì nó có nhiều chức năng vượt trội, giúp xây dựng các ứng dụng phức tạp dễ dàng hơn. Django phù hợp nhất cho các dự án lớn hơn với nhiều tính năng. Các tính năng có thể quá mức cần thiết cho các ứng dụng nhỏ hơn

Nếu bạn chưa quen với lập trình web, Flask là một nơi tuyệt vời để bắt đầu. Nhiều trang web được xây dựng bằng Flask và nhận được rất nhiều lưu lượng truy cập, mặc dù không nhiều như các trang web dựa trên Django. Nếu bạn muốn kiểm soát chính xác, bạn nên sử dụng bình, trong khi nhà phát triển Django dựa vào một cộng đồng lớn để tạo ra các trang web độc đáo

17. Đề cập đến sự khác biệt giữa Django, Kim tự tháp và Flask

Flask là một “micro framework” được thiết kế cho các ứng dụng nhỏ hơn với ít yêu cầu hơn. Kim tự tháp và Django đều hướng đến các dự án lớn hơn, nhưng chúng tiếp cận tính mở rộng và tính linh hoạt theo những cách khác nhau.  

Kim tự tháp được thiết kế linh hoạt, cho phép nhà phát triển sử dụng các công cụ tốt nhất cho dự án của họ. Điều này có nghĩa là nhà phát triển có thể chọn cơ sở dữ liệu, cấu trúc URL, kiểu tạo khuôn mẫu và các tùy chọn khác. Django mong muốn bao gồm tất cả các loại pin mà một ứng dụng web sẽ yêu cầu, vì vậy các lập trình viên chỉ cần mở hộp và bắt đầu làm việc, mang theo nhiều thành phần của Django khi họ sử dụng

Django bao gồm một ORM theo mặc định, nhưng Pyramid và Flask cung cấp cho nhà phát triển quyền kiểm soát cách thức [và liệu] dữ liệu của họ có được lưu trữ hay không. SQLAlchemy là ORM phổ biến nhất cho các ứng dụng web không phải Django, nhưng có rất nhiều tùy chọn thay thế, từ DynamoDB và MongoDB đến tính bền vững cục bộ đơn giản như LevelDB hoặc SQLite thông thường. Kim tự tháp được thiết kế để hoạt động với bất kỳ loại lớp kiên trì nào, ngay cả những lớp chưa được hình thành

DjangoPyramidFlaskĐó là một khung công tác python. Nó giống như DjangoNó là một micro-framework. Nó được sử dụng để xây dựng các ứng dụng lớn. Nó giống như DjangoNó được sử dụng để tạo một ứng dụng nhỏ. Nó bao gồm một ORM. Nó cung cấp tính linh hoạt và các công cụ phù hợp. Nó không yêu cầu thư viện bên ngoài

18. Thảo luận về kiến ​​trúc Django

Django có kiến ​​trúc MVC [Model-View-Controller], được chia thành ba phần

1. Mô hình

The Model, which is represented by a database, is the logical data structure that underpins the whole programme [generally relational databases such as MySql, Postgres]

2. Khung nhìn

Chế độ xem là giao diện người dùng hoặc những gì bạn thấy khi truy cập trang web trong trình duyệt của mình. Các tệp HTML/CSS/Javascript được sử dụng để đại diện cho chúng

3. Bộ điều khiển

Controller là cầu nối giữa view và model, nó có nhiệm vụ truyền dữ liệu từ model sang view

Ứng dụng của bạn sẽ xoay quanh mô hình bằng MVC, hiển thị hoặc thay đổi nó

19. Giải thích phạm vi trong Python?

Hãy coi phạm vi là người cha của một gia đình; . Một định nghĩa chính thức sẽ là đây là một khối mã theo đó cho dù bạn khai báo bao nhiêu đối tượng thì chúng vẫn có liên quan. Một vài ví dụ tương tự được đưa ra dưới đây

  • Phạm vi địa phương. Khi bạn tạo một biến bên trong một hàm thuộc phạm vi cục bộ của chính hàm đó và nó sẽ chỉ được sử dụng bên trong hàm đó

Thí dụ.    


def harshit_fun[]:
y = 100
print [y]

harshit_func[]
100
  • Phạm vi toàn cầu. Khi một biến được tạo bên trong phần thân chính của mã python, nó được gọi là phạm vi toàn cầu. Phần tốt nhất về phạm vi toàn cầu là chúng có thể truy cập được trong bất kỳ phần nào của mã python từ bất kỳ phạm vi nào là toàn cầu hoặc cục bộ

Thí dụ.  

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
  • Hàm lồng nhau. Đây còn được gọi là hàm bên trong hàm, như đã nêu trong ví dụ trên biến phạm vi cục bộ y không khả dụng bên ngoài hàm nhưng bên trong bất kỳ hàm nào bên trong hàm khác

Thí dụ

def first_func[]:
y = 100
def nested_func1[]:
print[y]
nested_func1[]
first_func[]
  • Phạm vi cấp độ mô-đun. Điều này về cơ bản đề cập đến các đối tượng toàn cầu của mô-đun hiện tại có thể truy cập trong chương trình
  • Phạm vi ngoài cùng. Đây là một tham chiếu đến tất cả các tên dựng sẵn mà bạn có thể gọi trong chương trình

20. Liệt kê các kiểu dữ liệu dựng sẵn phổ biến trong Python?

Đưa ra dưới đây là các kiểu dữ liệu tích hợp được sử dụng phổ biến nhất

số. Bao gồm các số nguyên, số dấu phẩy động và số phức

Danh sách. Chúng ta đã thấy một chút về danh sách, để định nghĩa một cách chính thức, danh sách là một dãy các mục có thể thay đổi được sắp xếp theo thứ tự, các phần tử bên trong danh sách cũng có thể thuộc các kiểu dữ liệu khác nhau

Thí dụ

list = [100, “Great Learning”, 30]

bộ dữ liệu. Đây cũng là một chuỗi các phần tử được sắp xếp theo thứ tự nhưng không giống như danh sách, các bộ dữ liệu là bất biến, nghĩa là nó không thể thay đổi sau khi được khai báo

Thí dụ

tup_2 = [100, “Great Learning”, 20] 

Chuỗi. Đây được gọi là dãy ký tự được khai báo trong dấu nháy đơn hoặc nháy kép

Thí dụ

“Hi, I work at great learning”
‘Hi, I work at great learning’

bộ. Bộ về cơ bản là bộ sưu tập các mặt hàng duy nhất trong đó thứ tự không đồng nhất

Thí dụ

set = {1,2,3}

Từ điển. Từ điển luôn lưu trữ các giá trị trong các cặp khóa và giá trị trong đó mỗi giá trị có thể được truy cập bằng khóa cụ thể của nó

Thí dụ

[12] harshit = {1:’video_games’, 2:’sports’, 3:’content’} 

Boolean. Chỉ có hai giá trị boolean. Đúng và sai

21. Các thuộc tính toàn cầu, được bảo vệ và riêng tư trong Python là gì?

Các thuộc tính của một lớp còn được gọi là các biến. Có ba công cụ sửa đổi truy cập trong Python cho các biến, cụ thể là

a. public – Các biến được khai báo là public có thể truy cập ở mọi nơi, bên trong hoặc bên ngoài lớp

b. riêng tư - Các biến được khai báo là riêng tư chỉ có thể truy cập được trong lớp hiện tại

c. được bảo vệ - Các biến được khai báo là được bảo vệ chỉ có thể truy cập được trong gói hiện tại

Các thuộc tính cũng được phân loại là

– Các thuộc tính cục bộ được xác định trong một khối mã/phương thức và chỉ có thể được truy cập trong khối mã/phương thức đó

– Các thuộc tính toàn cục được xác định bên ngoài khối mã/phương thức và có thể truy cập được ở mọi nơi

________số 8_______

22. Từ khóa trong Python là gì?

Từ khóa trong Python là những từ dành riêng được sử dụng làm định danh, tên hàm hoặc tên biến. Chúng giúp xác định cấu trúc và cú pháp của ngôn ngữ.  

Có tổng cộng 33 từ khóa trong Python 3. 7 có thể thay đổi trong phiên bản tiếp theo, tôi. e. , Trăn 3. 8. Một danh sách tất cả các từ khóa được cung cấp dưới đây

Từ khóa trong Python

FalseclassfinallyisreturnNonecontinueforlambdatryTruedeffromnonlocalwhileanddelglobalnotwithaselififoryieldassertelseimportpassbreakexcept

23. Sự khác biệt giữa danh sách và bộ dữ liệu trong Python là gì?

Danh sách và bộ dữ liệu là cấu trúc dữ liệu trong Python có thể lưu trữ một hoặc nhiều đối tượng hoặc giá trị. Sử dụng dấu ngoặc vuông, bạn có thể tạo danh sách chứa nhiều đối tượng trong một biến. Bộ dữ liệu, giống như mảng, có thể chứa nhiều phần tử trong một biến duy nhất và được xác định bằng dấu ngoặc đơn

Danh sách                            Danh sách bộ dữ liệu có thể thay đổi. Tuples là bất biến. The impacts of iterations are Time Consuming. Lặp đi lặp lại có tác dụng làm cho mọi thứ diễn ra nhanh hơn. The list is more convenient for actions like insertion and deletion. The items may be accessed using the tuple data type. Lists take up more memory. When compared to a list, a tuple uses less memory. There are numerous techniques built into lists. There aren’t many built-in methods in Tuple. Changes and faults that are unexpected are more likely to occur. It is difficult to take place in a tuple. They consume a lot of memory given the nature of this data structureThey consume less memorySyntax
list = [100, “Great Learning”, 30]Syntax. tup_2 = [100, “Great Learning”, 20]

24. How can you concatenate two tuples?

Let’s say we have two tuples like this ->

tup1 = [1,”a”,True]

tup2 = [4,5,6]

Concatenation of tuples means that we are adding the elements of one tuple at the end of another tuple

Now, let’s go ahead and concatenate tuple2 with tuple1

Mã số

tup1=[1,"a",True]
tup2=[4,5,6]
tup1+tup2

All you have to do is, use the ‘+’ operator between the two tuples and you’ll get the concatenated result

Similarly, let’s concatenate tuple1 with tuple2

Mã số

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
0

25. What are functions in Python?

Ans. Functions in Python refer to blocks that have organized, and reusable codes to perform single, and related events. Functions are important to create better modularity for applications that reuse a high degree of coding. Python has a number of built-in functions like print[]. However, it also allows you to create user-defined functions

26. How can you initialize a 5*5 numpy array with only zeroes?

We will be using the . zeros[] method

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
1

Use np. zeros[] và chuyển vào các kích thước bên trong nó. Since we want a 5*5 matrix, we will pass [5,5] inside the . zeros[] method

27. What are Pandas?

Pandas is an open-source python library that has a very rich set of data structures for data-based operations. Pandas with their cool features fit in every role of data operation, whether it be academics or solving complex business problems. Pandas can deal with a large variety of files and are one of the most important tools to have a grip on

Learn More About Python Pandas

Python Pandas Free Courses

28. What are data frames?

A pandas dataframe is a data structure in pandas that is mutable. Pandas have support for heterogeneous data which is arranged across two axes. [ rows and columns]

Reading files into pandas. -

12Import pandas as pddf=p. read_csv[“mydata. csv”]


Here, df is a pandas data frame. read_csv[] is used to read a comma-delimited file as a dataframe in pandas

29. What is a Pandas Series?

Series is a one-dimensional panda’s data structure that can data of almost any type. It resembles an excel column. It supports multiple operations and is used for single-dimensional data operations

Tạo một chuỗi từ dữ liệu

Mã số

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
2

30. Bạn hiểu gì về pandas groupby?

Nhóm gấu trúc là một tính năng được gấu trúc hỗ trợ, được sử dụng để phân tách và nhóm một đối tượng. Giống như nhóm sql/mysql/oracle bởi nó được sử dụng để nhóm dữ liệu theo lớp và các thực thể có thể được sử dụng thêm để tổng hợp. A dataframe can be grouped by one or more columns

Mã số

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
3

Để thực hiện groupby gõ mã sau

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
4

31. Làm cách nào để tạo một khung dữ liệu từ danh sách?

Để tạo một khung dữ liệu từ danh sách,

1] tạo một khung dữ liệu trống
2] add lists as individuals columns to the list

Mã số

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
5

32. How to create a data frame from a dictionary?

A dictionary can be directly passed as an argument to the DataFrame[] function to create the data frame

Mã số

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
6


33. How to combine dataframes in pandas?

Two different data frames can be stacked either horizontally or vertically by the concat[], append[], and join[] functions in pandas

Concat works best when the data frames have the same columns and can be used for concatenation of data having similar fields and is basically vertical stacking of dataframes into a single dataframe

Append[] is used for horizontal stacking of data frames. If two tables[dataframes] are to be merged together then this is the best concatenation function

Join is used when we need to extract data from different dataframes which are having one or more common columns. The stacking is horizontal in this case

Before going through the questions, here’s a quick video to help you refresh your memory on Python.  

34. What kind of joins does pandas offer?

Pandas have a left join, inner join, right join, and outer join

35. How to merge dataframes in pandas?

Merging depends on the type and fields of different dataframes being merged. If data has similar fields data is merged along axis 0 else they are merged along axis 1

36. Give the below dataframe drop all rows having Nan

The dropna function can be used to do that

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
7

37. How to access the first five entries of a dataframe?

By using the head[5] function we can get the top five entries of a dataframe. By default df. head[] returns the top 5 rows. To get the top n rows df. đầu [n] sẽ được sử dụng

38. How to access the last five entries of a dataframe?

By using the tail[5] function we can get the top five entries of a dataframe. By default df. tail[] returns the top 5 rows. To get the last n rows df. tail[n] will be used

39. How to fetch a data entry from a pandas dataframe using a given value in index?

To fetch a row from a dataframe given index x, we can use loc

Df. loc[10] where 10 is the value of the index

Mã số

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
8

40. What are comments and how can you add comments in Python?

Comments in Python refer to a piece of text intended for information. It is especially relevant when more than one person works on a set of codes. It can be used to analyse code, leave feedback, and debug it. There are two types of comments which includes

  1. Single-line comment
  2. Multiple-line comment

Codes needed for adding a comment

#Note –single line comment

“””Note

Note

Note”””—–multiline comment

41. What is a dictionary in Python? Give an example

A Python dictionary is a collection of items in no particular order. Python dictionaries are written in curly brackets with keys and values. Dictionaries are optimised to retrieve values for known keys

Example

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
9

42. What is the difference between a tuple and a dictionary?

One major difference between a tuple and a dictionary is that a dictionary is mutable while a tuple is not. Meaning the content of a dictionary can be changed without changing its identity, but in a tuple, that’s not possible

43. Find out the mean, median and standard deviation of this numpy array -> np. array[[1,5,3,100,4,48]]

def first_func[]:
y = 100
def nested_func1[]:
print[y]
nested_func1[]
first_func[]
0

44. What is a classifier?

Một bộ phân loại được sử dụng để dự đoán lớp của bất kỳ điểm dữ liệu nào. Trình phân loại là các giả thuyết đặc biệt được sử dụng để gán nhãn lớp cho bất kỳ điểm dữ liệu cụ thể nào. Một bộ phân loại thường sử dụng dữ liệu huấn luyện để hiểu mối quan hệ giữa các biến đầu vào và lớp. Phân loại là một phương pháp được sử dụng trong học có giám sát trong Machine Learning

45. In Python how do you convert a string into lowercase?

All the upper cases in a string can be converted into lowercase by using the method. string. lower[]

ex

def first_func[]:
y = 100
def nested_func1[]:
print[y]
nested_func1[]
first_func[]
1

o/p. greatlearning

46. How do you get a list of all the keys in a dictionary?

One of the ways we can get a list of keys is by using. dict. keys[]

This method returns all the available keys in the dictionary

def first_func[]:
y = 100
def nested_func1[]:
print[y]
nested_func1[]
first_func[]
2

o/p. [1, 2, 3]

47. How can you capitalize the first letter of a string?

We can use the capitalize[] function to capitalize the first character of a string. If the first character is already in the capital then it returns the original string

Syntax

def first_func[]:
y = 100
def nested_func1[]:
print[y]
nested_func1[]
first_func[]
3

ex

def first_func[]:
y = 100
def nested_func1[]:
print[y]
nested_func1[]
first_func[]
4

o/p. Greatlearning

48. How can you insert an element at a given index in Python?

Python has an inbuilt function called the insert[] function

It can be used used to insert an element at a given index

Syntax

def first_func[]:
y = 100
def nested_func1[]:
print[y]
nested_func1[]
first_func[]
5

ex

def first_func[]:
y = 100
def nested_func1[]:
print[y]
nested_func1[]
first_func[]
6

o/p. [0,1,2,3,4,5,10,6,7]

49. How will you remove duplicate elements from a list?

There are various methods to remove duplicate elements from a list. But, the most common one is, converting the list into a set by using the set[] function and using the list[] function to convert it back to a list if required

ex

def first_func[]:
y = 100
def nested_func1[]:
print[y]
nested_func1[]
first_func[]
7

o/p. The list without duplicates . [2, 4, 6, 7]

50. What is recursion?

Recursion is a function calling itself one or more times in it body. One very important condition a recursive function should have to be used in a program is, it should terminate, else there would be a problem of an infinite loop

51. Explain Python List Comprehension

List comprehensions are used for transforming one list into another list. Elements can be conditionally included in the new list and each element can be transformed as needed. It consists of an expression leading to a for clause, enclosed in brackets

For ex

def first_func[]:
y = 100
def nested_func1[]:
print[y]
nested_func1[]
first_func[]
8

52. What is the bytes[] function?

The bytes[] function returns a bytes object. It is used to convert objects into bytes objects or create empty bytes objects of the specified size

53. What are the different types of operators in Python?

Python has the following basic operators

Arithmetic [Addition[+], Substraction[-], Multiplication[*], Division[/], Modulus[%] ], Relational [, =, ==, !=, ],
Assignment [=. +=, -=, /=, *=, %= ],
Logical [and, or not ], Membership, Identity, and Bitwise Operators

54. What is the ‘with statement’?

The “with” statement in python is used in exception handling. A file can be opened and closed while executing a block of code, containing the “with” statement. , without using the close[] function. Về cơ bản, nó làm cho mã dễ đọc hơn nhiều

55. What is a map[] function in Python?

The map[] function in Python is used for applying a function on all elements of a specified iterable. It consists of two parameters, function and iterable. The function is taken as an argument and then applied to all the elements of an iterable[passed as the second argument]. An object list is returned as a result

def first_func[]:
y = 100
def nested_func1[]:
print[y]
nested_func1[]
first_func[]
9

o/p. 30,50,70,90

56. What is __init__ in Python?

_init_ methodology is a reserved method in Python aka constructor in OOP. When an object is created from a class and _init_ methodology is called to access the class attributes

Also Read. Python __init__- An Overview

57. What are the tools present to perform static analysis?

The two static analysis tools used to find bugs in Python are Pychecker and Pylint. Pychecker detects bugs from the source code and warns about its style and complexity. While Pylint checks whether the module matches upto a coding standard

58. What is pass in Python?

Pass is a statement that does nothing when executed. In other words, it is a Null statement. This statement is not ignored by the interpreter, but the statement results in no operation. It is used when you do not want any command to execute but a statement is required

59. How can an object be copied in Python?

Not all objects can be copied in Python, but most can. We can use the “=” operator to copy an object to a variable

ex

list = [100, “Great Learning”, 30]
0

60. How can a number be converted to a string?

The inbuilt function str[] can be used to convert a number to a string

61. What are modules and packages in Python?

Modules are the way to structure a program. Each Python program file is a module, importing other attributes and objects. The folder of a program is a package of modules. A package can have modules or subfolders

62. What is the object[] function in Python?

In Python, the object[] function returns an empty object. New properties or methods cannot be added to this object

63. What is the difference between NumPy and SciPy?

NumPy stands for Numerical Python while SciPy stands for Scientific Python. NumPy is the basic library for defining arrays and simple mathematical problems, while SciPy is used for more complex problems like numerical integration and optimization and machine learning and so on

64. What does len[] do?

len[] is used to determine the length of a string, a list, an array, and so on

ex

list = [100, “Great Learning”, 30]
1

o/p. 13

65. Define encapsulation in Python?

Đóng gói có nghĩa là liên kết mã và dữ liệu với nhau. A Python class for example

66. What is the type [] in Python?

type[] is a built-in method that either returns the type of the object or returns a new type of object based on the arguments passed

ex

list = [100, “Great Learning”, 30]
2

o/p. int

67. What is the split[] function used for?

Hàm tách được sử dụng để tách một chuỗi thành các chuỗi ngắn hơn bằng cách sử dụng các dấu phân cách đã xác định

list = [100, “Great Learning”, 30]
3

o/p. [‘A’, ‘B’, ‘C’ ]

68. What are the built-in types does python provide?

Python has following built-in data types

Numbers. Python identifies three types of numbers

  1. Integer. All positive and negative numbers without a fractional part
  2. Float. Any real number with floating-point representation
  3. Complex numbers. A number with a real and imaginary component represented as x+yj. x and y are floats and j is -1[square root of -1 called an imaginary number]

Boolean. The Boolean data type is a data type that has one of two possible values i. e. True or False. Note that ‘T’ and ‘F’ are capital letters

String. A string value is a collection of one or more characters put in single, double or triple quotes

List. A list object is an ordered collection of one or more data items that can be of different types, put in square brackets. A list is mutable and thus can be modified, we can add, edit or delete individual elements in a list

Set. An unordered collection of unique objects enclosed in curly brackets

Frozen set. They are like a set but immutable, which means we cannot modify their values once they are created

Dictionary. A dictionary object is unordered in which there is a key associated with each value and we can access each value through its key. A collection of such pairs is enclosed in curly brackets. For example {‘First Name’. ’Tom’, ’last name’. ’Hardy’} Note that Number values, strings, and tuples are immutable while List or Dictionary objects are mutable

69. What is docstring in Python?

Python docstrings are the string literals enclosed in triple quotes that appear right after the definition of a function, method, class, or module. These are generally used to describe the functionality of a particular function, method, class, or module. We can access these docstrings using the __doc__ attribute

Here is an example

list = [100, “Great Learning”, 30]
4

Ouput. Takes in a number n, returns the square of n

70. How to Reverse a String in Python?

In Python, there are no in-built functions that help us reverse a string. Chúng ta cần sử dụng thao tác cắt mảng cho cùng một

1str_reverse = string[. -1]

Learn more. How To Reverse a String In Python

71. How to check the Python Version in CMD?

To check the Python Version in CMD, press CMD + Space. This opens Spotlight. Here, type “terminal” and press enter. To execute the command, type python –version or python -V and press enter. This will return the python version in the next line below the command

72. Is Python case sensitive when dealing with identifiers?

Yes. Python is case-sensitive when dealing with identifiers. It is a case-sensitive language. Thus, variable and Variable would not be the same

Python Interview Questions for Experienced

This section on Python Interview Questions for Experienced covers 20+ questions that are commonly asked during the interview process for landing a job as a Python experienced professional. These commonly asked questions can help you brush up your skills and know what to expect in your upcoming interviews.  

73. How to create a new column in pandas by using values from other columns?

We can perform column based mathematical operations on a pandas dataframe. Pandas columns containing numeric values can be operated upon by operators

Mã số

list = [100, “Great Learning”, 30]
5

đầu ra

74. What are the different functions that can be used by grouby in pandas ?

grouby[] in pandas can be used with multiple aggregate functions. Some of which are sum[],mean[], count[],std[]

Data is divided into groups based on categories and then the data in these individual groups can be aggregated by the aforementioned functions

75. How to delete a column or group of columns in pandas? Given the below dataframe drop column “col1”

drop[] function can be used to delete the columns from a dataframe

list = [100, “Great Learning”, 30]
6

76. Given the following data frame drop rows having column values as A

Mã số

list = [100, “Great Learning”, 30]
7

77. What is Reindexing in pandas?

Reindexing is the process of re-assigning the index of a pandas dataframe

Mã số

list = [100, “Great Learning”, 30]
8

78. What do you understand about the lambda function? Create a lambda function which will print the sum of all the elements in this list -> [5, 8, 10, 20, 50, 100]

Lambda functions are anonymous functions in Python. They are defined using the keyword lambda. Lambda functions can take any number of arguments, but they can only have one expression

list = [100, “Great Learning”, 30]
9

79. What is vstack[] in numpy? Give an example

vstack[] is a function to align rows vertically. All rows must have the same number of elements

Mã số

tup_2 = [100, “Great Learning”, 20] 
0

80. How to remove spaces from a string in Python?

Spaces can be removed from a string in python by using strip[] or replace[] functions. Strip[] function is used to remove the leading and trailing white spaces while the replace[] function is used to remove all the white spaces in the string

tup_2 = [100, “Great Learning”, 20] 
1

o/p. greatlearning

81. Explain the file processing modes that Python supports

There are three file processing modes in Python. read-only[r], write-only[w], read-write[rw] and append [a]. So, if you are opening a text file in say, read mode. The preceding modes become “rt” for read-only, “wt” for write and so on. Similarly, a binary file can be opened by specifying “b” along with the file accessing flags [“r”, “w”, “rw” and “a”] preceding it

82. What is pickling and unpickling?

Pickling là quá trình chuyển đổi cấu trúc phân cấp đối tượng Python thành luồng byte để lưu trữ vào cơ sở dữ liệu. It is also known as serialization. Unpickling is the reverse of pickling. The byte stream is converted back into an object hierarchy

83. How is memory managed in Python?

This is one of the most commonly asked python interview questions

Quản lý bộ nhớ trong python bao gồm một đống riêng chứa tất cả các đối tượng và cấu trúc dữ liệu. The heap is managed by the interpreter and the programmer does not have access to it at all. Trình quản lý bộ nhớ Python thực hiện tất cả việc cấp phát bộ nhớ. Moreover, there is an inbuilt garbage collector that recycles and frees memory for the heap space

84. What is unittest in Python?

Unittest là một khung kiểm tra đơn vị trong Python. It supports sharing of setup and shutdown code for tests, aggregation of tests into collections,test automation, and independence of the tests from the reporting framework

85. How do you delete a file in Python?

Các tệp có thể bị xóa trong Python bằng cách sử dụng lệnh os. xóa [tên tệp] hoặc os. hủy liên kết [tên tệp]

86. Làm thế nào để bạn tạo một lớp trống trong Python?

Để tạo một lớp trống, chúng ta có thể sử dụng lệnh pass sau định nghĩa của đối tượng lớp. Vượt qua là một câu lệnh trong Python không làm gì cả

87. Trình trang trí Python là gì?

Trình trang trí là các hàm lấy một hàm khác làm đối số để sửa đổi hành vi của nó mà không thay đổi chính hàm đó. Những điều này rất hữu ích khi chúng ta muốn tự động tăng chức năng của một chức năng mà không cần thay đổi nó

Here is an example

tup_2 = [100, “Great Learning”, 20] 
2

Ở đây smart_divide là một chức năng trang trí được sử dụng để thêm chức năng vào chức năng phân chia đơn giản

88. Ngôn ngữ gõ động là gì?

Kiểm tra kiểu là một phần quan trọng của bất kỳ ngôn ngữ lập trình nào nhằm đảm bảo lỗi kiểu tối thiểu. Loại được xác định cho các biến được kiểm tra tại thời gian biên dịch hoặc thời gian chạy. Khi kiểm tra kiểu được thực hiện tại thời điểm biên dịch thì nó được gọi là ngôn ngữ kiểu tĩnh và khi kiểm tra kiểu được thực hiện trong thời gian chạy, nó được gọi là ngôn ngữ kiểu động

  1. Trong ngôn ngữ kiểu động, các đối tượng được ràng buộc kiểu bởi các phép gán trong thời gian chạy.  
  2. Các ngôn ngữ lập trình được nhập động tạo ra mã ít được tối ưu hóa hơn một cách tương đối
  3. Trong các ngôn ngữ có kiểu động, không cần xác định kiểu cho các biến trước khi sử dụng chúng. Do đó, nó có thể được phân bổ động

89. cắt lát trong Python là gì?

Cắt lát trong Python đề cập đến việc truy cập các phần của chuỗi. Trình tự có thể là bất kỳ đối tượng có thể thay đổi và lặp lại nào. slice[ ] là một hàm được sử dụng trong Python để chia chuỗi đã cho thành các phân đoạn theo yêu cầu.  

Có hai biến thể của việc sử dụng hàm lát. Cú pháp cắt trong python.  

  1. lát [bắt đầu, dừng]
  2. silica [bắt đầu, dừng, bước]

Bán tại

tup_2 = [100, “Great Learning”, 20] 
3

90. Sự khác biệt giữa Mảng Python và danh sách là gì?

Mảng và Danh sách Python đều là tập hợp các phần tử được sắp xếp theo thứ tự và có thể thay đổi, nhưng sự khác biệt nằm ở cách làm việc với chúng

Mảng lưu trữ dữ liệu không đồng nhất khi được nhập từ mô-đun mảng, nhưng mảng có thể lưu trữ dữ liệu đồng nhất được nhập từ mô-đun numpy. Nhưng danh sách có thể lưu trữ dữ liệu không đồng nhất và để sử dụng danh sách, danh sách không phải nhập từ bất kỳ mô-đun nào

tup_2 = [100, “Great Learning”, 20] 
4

Hoặc là,

tup_2 = [100, “Great Learning”, 20] 
5
  1. Mảng phải được khai báo trước khi sử dụng nhưng không cần khai báo danh sách
  2. Các phép toán số dễ thực hiện hơn trên mảng so với danh sách

91. Độ phân giải phạm vi trong Python là gì?

Khả năng truy cập của biến được xác định trong python theo vị trí khai báo biến, được gọi là phạm vi của biến trong python. Scope Resolution refers to the order in which these variables are looked for a name to variable matching. Following is the scope defined in python for variable declaration

a. Local scope – The variable declared inside a loop, the function body is accessible only within that function or loop

b. Global scope – The variable is declared outside any other code at the topmost level and is accessible everywhere

c. Enclosing scope – The variable is declared inside an enclosing function, accessible only within that enclosing function

d. Built-in Scope – The variable declared inside the inbuilt functions of various modules of python has the built-in scope and is accessible only within that particular module

The scope resolution for any variable is made in java in a particular order, and that order is

Local Scope -> enclosing scope -> global scope -> built-in scope

92. What are Dict and List comprehensions?

List comprehensions provide a more compact and elegant way to create lists than for-loops, and also a new list can be created from existing lists

The syntax used is as follows

tup_2 = [100, “Great Learning”, 20] 
6

Hoặc là,

tup_2 = [100, “Great Learning”, 20] 
7

Bán tại

tup_2 = [100, “Great Learning”, 20] 
8
tup_2 = [100, “Great Learning”, 20] 
9

Dictionary comprehensions provide a more compact and elegant way to create a dictionary, and also, a new dictionary can be created from existing dictionaries

The syntax used is

“Hi, I work at great learning”
‘Hi, I work at great learning’
0

Bán tại

“Hi, I work at great learning”
‘Hi, I work at great learning’
1

93. What is the difference between xrange and range in Python?

range[] and xrange[] are inbuilt functions in python used to generate integer numbers in the specified range. The difference between the two can be understood if python version 2. 0 is used because the python version 3. 0 xrange[] function is re-implemented as the range[] function itself

With respect to python 2. 0, the difference between range and xrange function is as follows

  1. range[] takes more memory comparatively
  2. xrange[], execution speed is faster comparatively
  3. range [] returns a list of integers and xrange[] returns a generator object

Thí dụ

“Hi, I work at great learning”
‘Hi, I work at great learning’
2

94. What is the difference between . py and . pyc files?

py are the source code files in python that the python interpreter interprets

pyc are the compiled files that are bytecodes generated by the python compiler, but . pyc files are only created for inbuilt modules/files

Python Programming Interview Questions

Apart from having theoretical knowledge, having practical experience and knowing programming interview questions is a crucial part of the interview process. It helps the recruiters understand your hands-on experience. These are 45+ of the most commonly asked Python programming interview questions.  

Here is a pictorial representation of how to generate the python programming output

95. You have this covid-19 dataset below

This is one of the most commonly asked python interview questions

From this dataset, how will you make a bar-plot for the top 5 states having maximum confirmed cases as of 17=07-2020?

sol

“Hi, I work at great learning”
‘Hi, I work at great learning’
3

Code explanation

We start off by taking only the required columns with this command

“Hi, I work at great learning”
‘Hi, I work at great learning’
4

Then, we go ahead and rename the columns

“Hi, I work at great learning”
‘Hi, I work at great learning’
5

After that, we extract only those records, where the date is equal to 17th July

“Hi, I work at great learning”
‘Hi, I work at great learning’
6

Then, we go ahead and select the top 5 states with maximum no. of covid cases

“Hi, I work at great learning”
‘Hi, I work at great learning’
7

Finally, we go ahead and make a bar-plot with this

“Hi, I work at great learning”
‘Hi, I work at great learning’
8

Here, we are using the seaborn library to make the bar plot. The “State” column is mapped onto the x-axis and the “confirmed” column is mapped onto the y-axis. The color of the bars is determined by the “state” column

96. From this covid-19 dataset

How can you make a bar plot for the top 5 states with the most amount of deaths?

“Hi, I work at great learning”
‘Hi, I work at great learning’
9

Code Explanation

Chúng tôi bắt đầu bằng cách sắp xếp khung dữ liệu của mình theo thứ tự giảm dần w. r. t the “deaths” column

set = {1,2,3}
0

Then, we go ahead and make the bar-plot with the help of seaborn library

set = {1,2,3}
1

Here, we are mapping the “state” column onto the x-axis and the “deaths” column onto the y-axis

97. Từ bộ dữ liệu covid-19 này

Làm cách nào bạn có thể tạo biểu đồ đường biểu thị các trường hợp được xác nhận theo ngày?

sol

set = {1,2,3}
2

Code Explanation

Chúng tôi bắt đầu bằng cách trích xuất tất cả các bản ghi có trạng thái bằng “Maharashtra”

set = {1,2,3}
3

Sau đó, chúng tôi tiếp tục và tạo một biểu đồ đường bằng cách sử dụng thư viện seaborn

set = {1,2,3}
4

Ở đây, chúng tôi ánh xạ cột “ngày” lên trục x và cột “đã xác nhận” vào trục y

98. Trên tập dữ liệu “Maharashtra” này

Bạn sẽ triển khai thuật toán hồi quy tuyến tính như thế nào với “ngày” là biến độc lập và “đã xác nhận” là biến phụ thuộc? . r. ngày t

set = {1,2,3}
5

giải mã

Chúng tôi sẽ bắt đầu bằng cách chuyển đổi ngày thành loại thứ tự

set = {1,2,3}
6

Điều này được thực hiện bởi vì chúng tôi không thể xây dựng thuật toán hồi quy tuyến tính trên đầu cột ngày

Sau đó, chúng tôi tiếp tục và chia tập dữ liệu thành tập huấn luyện và tập kiểm tra

set = {1,2,3}
7

Cuối cùng, chúng tôi tiếp tục và xây dựng mô hình

set = {1,2,3}
8

99. Trên tập dữ liệu customer_churn này

This is one of the most commonly asked python interview questions

Xây dựng mô hình tuần tự Keras để tìm hiểu xem có bao nhiêu khách hàng sẽ xuất hiện trên cơ sở nhiệm kỳ của khách hàng?

set = {1,2,3}
9

Code explanation

Chúng tôi sẽ bắt đầu bằng cách nhập các thư viện cần thiết

[12] harshit = {1:’video_games’, 2:’sports’, 3:’content’} 
0

Sau đó, chúng tôi tiếp tục và xây dựng cấu trúc của mô hình tuần tự

[12] harshit = {1:’video_games’, 2:’sports’, 3:’content’} 
1

Cuối cùng, chúng ta sẽ tiếp tục và dự đoán các giá trị

[12] harshit = {1:’video_games’, 2:’sports’, 3:’content’} 
2

100. Trên tập dữ liệu iris này

Xây dựng mô hình phân loại cây quyết định, trong đó biến phụ thuộc là “Species” và biến độc lập là “Sepal. Chiều dài"

[12] harshit = {1:’video_games’, 2:’sports’, 3:’content’} 
3

Code explanation

Chúng tôi bắt đầu bằng cách trích xuất biến độc lập và biến phụ thuộc

[12] harshit = {1:’video_games’, 2:’sports’, 3:’content’} 
4

Sau đó, chúng tôi tiếp tục và chia dữ liệu thành tập huấn luyện và kiểm tra

[12] harshit = {1:’video_games’, 2:’sports’, 3:’content’} 
5

Sau đó, chúng tôi tiếp tục và xây dựng mô hình

[12] harshit = {1:’video_games’, 2:’sports’, 3:’content’} 
6

Cuối cùng, chúng tôi xây dựng ma trận nhầm lẫn

[12] harshit = {1:’video_games’, 2:’sports’, 3:’content’} 
7

101. Trên tập dữ liệu iris này

Xây dựng mô hình hồi quy cây quyết định trong đó biến độc lập là “chiều dài cánh hoa” và biến phụ thuộc là “chiều dài đài hoa”

[12] harshit = {1:’video_games’, 2:’sports’, 3:’content’} 
8

102. Bạn sẽ cạo dữ liệu từ trang web “cricbuzz” như thế nào?

[12] harshit = {1:’video_games’, 2:’sports’, 3:’content’} 
9

103. Viết một hàm do người dùng định nghĩa để thực hiện định lý giới hạn trung tâm. Bạn phải thực hiện định lý giới hạn trung tâm trên tập dữ liệu “bảo hiểm” này

Bạn cũng phải xây dựng hai biểu đồ về "Phân phối lấy mẫu của BMI" và "Phân phối dân số của  BMI"

class Mobile:
    m1 = "Samsung Mobiles" //Global attributes
    def price[self]:
        m2 = "Costly mobiles"   //Local attributes
        return m2
Sam_m = Mobile[]
print[Sam_m.m1]
0

Code Explanation

Chúng tôi bắt đầu bằng cách nhập khẩu bảo hiểm. csv bằng lệnh này

class Mobile:
    m1 = "Samsung Mobiles" //Global attributes
    def price[self]:
        m2 = "Costly mobiles"   //Local attributes
        return m2
Sam_m = Mobile[]
print[Sam_m.m1]
1

Sau đó, chúng tôi tiếp tục và xác định phương pháp định lý giới hạn trung tâm

class Mobile:
    m1 = "Samsung Mobiles" //Global attributes
    def price[self]:
        m2 = "Costly mobiles"   //Local attributes
        return m2
Sam_m = Mobile[]
print[Sam_m.m1]
2

Phương pháp này bao gồm các tham số này

  • Dữ liệu
  • N_samples
  • Cỡ mẫu
  • giá trị tối thiểu
  • Giá trị tối đa

Bên trong phương thức này, chúng tôi nhập tất cả các thư viện cần thiết

class Mobile:
    m1 = "Samsung Mobiles" //Global attributes
    def price[self]:
        m2 = "Costly mobiles"   //Local attributes
        return m2
Sam_m = Mobile[]
print[Sam_m.m1]
3

Sau đó, chúng tôi tiếp tục và tạo ô phụ đầu tiên cho “Lấy mẫu phân phối bmi”

class Mobile:
    m1 = "Samsung Mobiles" //Global attributes
    def price[self]:
        m2 = "Costly mobiles"   //Local attributes
        return m2
Sam_m = Mobile[]
print[Sam_m.m1]
4

Cuối cùng, chúng tôi tạo ô phụ cho “Phân bố dân số của BMI”

class Mobile:
    m1 = "Samsung Mobiles" //Global attributes
    def price[self]:
        m2 = "Costly mobiles"   //Local attributes
        return m2
Sam_m = Mobile[]
print[Sam_m.m1]
5

104. Viết mã để thực hiện phân tích tình cảm trên các đánh giá của amazon

Đây là một trong những câu hỏi phỏng vấn trăn phổ biến nhất

class Mobile:
    m1 = "Samsung Mobiles" //Global attributes
    def price[self]:
        m2 = "Costly mobiles"   //Local attributes
        return m2
Sam_m = Mobile[]
print[Sam_m.m1]
6

105. Thực hiện một biểu đồ xác suất bằng cách sử dụng numpy và matplotlib

sol

class Mobile:
    m1 = "Samsung Mobiles" //Global attributes
    def price[self]:
        m2 = "Costly mobiles"   //Local attributes
        return m2
Sam_m = Mobile[]
print[Sam_m.m1]
7

106. Thực hiện nhiều hồi quy tuyến tính trên bộ dữ liệu mống mắt này

Các biến độc lập phải là “Sepal. Chiều rộng”, “Cánh hoa. Chiều dài”, “Cánh hoa. Chiều rộng”, trong khi biến phụ thuộc phải là “Sepal. Chiều dài"

sol

class Mobile:
    m1 = "Samsung Mobiles" //Global attributes
    def price[self]:
        m2 = "Costly mobiles"   //Local attributes
        return m2
Sam_m = Mobile[]
print[Sam_m.m1]
8

giải mã

Chúng tôi bắt đầu bằng cách nhập các thư viện cần thiết

class Mobile:
    m1 = "Samsung Mobiles" //Global attributes
    def price[self]:
        m2 = "Costly mobiles"   //Local attributes
        return m2
Sam_m = Mobile[]
print[Sam_m.m1]
9

Sau đó, chúng tôi sẽ tiếp tục và trích xuất các biến độc lập và biến phụ thuộc

tup1=[1,"a",True]
tup2=[4,5,6]
tup1+tup2
0

Sau đó, chúng tôi chia dữ liệu thành tập huấn luyện và kiểm tra

tup1=[1,"a",True]
tup2=[4,5,6]
tup1+tup2
1

Sau đó, chúng tôi tiếp tục và xây dựng mô hình

tup1=[1,"a",True]
tup2=[4,5,6]
tup1+tup2
2

Cuối cùng, chúng ta sẽ tìm ra sai số bình phương trung bình

tup1=[1,"a",True]
tup2=[4,5,6]
tup1+tup2
3

107. Từ bộ dữ liệu gian lận tín dụng này

Tìm phần trăm giao dịch gian lận và không gian lận. Đồng thời xây dựng mô hình hồi quy logistic, để tìm hiểu xem giao dịch có gian lận hay không

sol

tup1=[1,"a",True]
tup2=[4,5,6]
tup1+tup2
4

108. Triển khai một CNN đơn giản trên tập dữ liệu MNIST bằng Keras. Sau đó, cũng thêm vào các lớp thả ra

sol

tup1=[1,"a",True]
tup2=[4,5,6]
tup1+tup2
5

109. Triển khai hệ thống đề xuất dựa trên mức độ phổ biến trên bộ dữ liệu ống kính phim này

tup1=[1,"a",True]
tup2=[4,5,6]
tup1+tup2
6

110. Triển khai thuật toán Bayes ngây thơ trên bộ dữ liệu bệnh tiểu đường

tup1=[1,"a",True]
tup2=[4,5,6]
tup1+tup2
7

Tuy nhiên, chúng tôi muốn thấy một mối tương quan trong biểu diễn đồ họa, vì vậy bên dưới là chức năng cho điều đó

tup1=[1,"a",True]
tup2=[4,5,6]
tup1+tup2
8

111. Làm cách nào bạn có thể tìm thấy các giá trị tối thiểu và tối đa có trong một bộ dữ liệu?

Giải pháp ->

Chúng ta có thể sử dụng hàm min[] trên đầu tuple để tìm ra giá trị nhỏ nhất có trong tuple

tup1=[1,"a",True]
tup2=[4,5,6]
tup1+tup2
9

đầu ra

1

Chúng tôi thấy rằng giá trị tối thiểu có trong bộ dữ liệu là 1

Tương tự với hàm min[] là hàm max[], hàm này sẽ giúp chúng ta tìm ra giá trị lớn nhất có trong bộ

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
00

đầu ra

5

Chúng tôi thấy rằng giá trị tối đa có trong bộ dữ liệu là 5

112. Nếu bạn có một danh sách như thế này -> [1,”a”,2,”b”,3,”c”]. Làm cách nào bạn có thể truy cập các phần tử thứ 2, thứ 4 và thứ 5 từ danh sách này?

Giải pháp ->

Chúng tôi sẽ bắt đầu bằng cách tạo một bộ dữ liệu bao gồm các chỉ số của các phần tử mà chúng tôi muốn truy cập

Sau đó, chúng tôi sẽ sử dụng vòng lặp for để duyệt qua các giá trị chỉ mục và in chúng ra

Dưới đây là toàn bộ mã cho quá trình

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
01

113. Nếu bạn có một danh sách như thế này -> [“sparta”,True,3+4j,False]. Làm thế nào bạn sẽ đảo ngược các yếu tố của danh sách này?

Giải pháp ->

Chúng ta có thể sử dụng hàm reverse[] trong danh sách

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
02

114. Nếu bạn có từ điển như thế này – > fruit={“Apple”. 10, "Cam". 20,"Chuối". 30,”Ổi”. 40}. Bạn sẽ cập nhật giá trị của 'Apple' từ 10 lên 100 như thế nào?

Giải pháp ->

Đây là cách bạn có thể làm điều đó

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
03

Nhập tên của khóa bên trong dấu ngoặc đơn và gán cho nó một giá trị mới

115. Nếu bạn có hai bộ như thế này -> s1 = {1,2,3,4,5,6}, s2 = {5,6,7,8,9}. Làm thế nào để bạn tìm thấy các yếu tố phổ biến trong các tập hợp này

Giải pháp ->

Bạn có thể sử dụng hàm giao [] để tìm các phần tử chung giữa hai tập hợp

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
04

Ta thấy các phần tử chung của hai tập hợp là 5 & 6

116. Viết chương trình in ra 2 bảng bằng vòng lặp while

Giải pháp ->

Dưới đây là mã để in ra 2 bảng

Mã số

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
05

đầu ra

Chúng tôi bắt đầu bằng cách khởi tạo hai biến 'i' và 'n'. 'i' được khởi tạo thành 1 và 'n' được khởi tạo thành '2'

Bên trong vòng lặp while, vì giá trị 'i' đi từ 1 đến 10 nên vòng lặp lặp lại 10 lần

Ban đầu n*i bằng 2*1, và chúng tôi in ra giá trị

Sau đó, giá trị 'i' được tăng lên và n*i trở thành 2*2. Chúng tôi tiếp tục và in nó ra

Quá trình này tiếp tục cho đến khi giá trị i trở thành 10

117. Viết hàm nhận vào một giá trị và in ra nếu nó là chẵn hay lẻ

Giải pháp ->

Đoạn mã dưới đây sẽ thực hiện công việc

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
06

Ở đây, chúng tôi bắt đầu bằng cách tạo một phương thức, với tên 'even_odd[]'. Hàm này nhận một tham số duy nhất và in ra nếu số được lấy là chẵn hay lẻ

Bây giờ, hãy gọi hàm

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
07

Chúng ta thấy rằng, khi 5 được truyền dưới dạng tham số vào hàm, chúng ta sẽ nhận được kết quả -> '5 là số lẻ'

118. Viết chương trình python in giai thừa của một số

This is one of the most commonly asked python interview questions

Giải pháp ->

Dưới đây là mã để in giai thừa của một số

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
08

Chúng tôi bắt đầu bằng cách lấy một đầu vào được lưu trữ trong 'num'. Sau đó, chúng tôi kiểm tra xem 'num' có nhỏ hơn 0 hay không và nếu nó thực sự nhỏ hơn 0, chúng tôi sẽ in ra 'Xin lỗi, giai thừa không tồn tại cho các số âm'

Sau đó, chúng tôi kiểm tra, nếu 'num' bằng 0, và đó là trường hợp, chúng tôi in ra 'Giai thừa của 0 là 1'

Ngược lại nếu ‘num’ lớn hơn 1 thì ta nhập vòng lặp for và tính giai thừa của số

119. Viết chương trình python kiểm tra xem số đã cho có phải là số đối xứng hay không

Giải pháp ->

Dưới đây là mã để Kiểm tra xem số đã cho có phải là palindrome hay không

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
09

Chúng tôi sẽ bắt đầu bằng cách lấy một đầu vào và lưu trữ nó trong 'n' và tạo một bản sao của nó trong 'temp'. Chúng tôi cũng sẽ khởi tạo một biến khác 'rev' thành 0.  

Sau đó, chúng tôi sẽ nhập một vòng lặp while sẽ tiếp tục cho đến khi 'n' trở thành 0.  

Trong vòng lặp, chúng tôi sẽ bắt đầu bằng cách chia 'n' cho 10 và sau đó lưu trữ phần còn lại trong 'dig'

Sau đó, chúng tôi sẽ nhân 'rev' với 10 và sau đó thêm 'dig' vào nó. Kết quả này sẽ được lưu lại trong ‘rev’

Tiếp tục, chúng tôi sẽ chia 'n' cho 10 và lưu kết quả trở lại trong 'n'

Khi vòng lặp for kết thúc, chúng ta sẽ so sánh giá trị của ‘rev’ và ‘temp’. Nếu chúng bằng nhau, chúng tôi sẽ in 'Số là một bảng màu', nếu không, chúng tôi sẽ in 'Số không phải là một bảng màu'

120. Viết chương trình python để in mẫu sau ->

Đây là một trong những câu hỏi phỏng vấn trăn phổ biến nhất

1

2 2

3 3 3

4 4 4 4

5 5 5 5 5

Giải pháp ->

Dưới đây là mã để in mẫu này

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
10

Chúng tôi đang giải quyết vấn đề với sự trợ giúp của vòng lặp for lồng nhau. Chúng ta sẽ có một vòng lặp for bên ngoài, đi từ 1 đến 5. Sau đó, chúng ta có một vòng lặp for bên trong, vòng lặp này sẽ in các số tương ứng

121. câu hỏi mẫu. In mẫu sau

#

# #

# # #

# # # #

# # # # #

Giải pháp ->

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
11

122. In mẫu sau

#

# #

# # #

# # # #

# # # # #

Giải pháp ->

Mã số

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
12

123. In mẫu sau

0

0 1

0 1 2

0 1 2 3

0 1 2 3 4

Giải pháp ->

Mã số.  

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
13

124. Print the following pattern

1

2 3

4 5 6

7 8 9 10

11 12 13 14 15

Giải pháp ->

Mã số

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
14

125. Print the following pattern

A

B B

C C C

D D D D

Giải pháp ->

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
15

126. Print the following pattern

A

B C

D E F

G H I J

K L M N O

P Q R S T U

Giải pháp ->

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
16

127. Print the following pattern

  #

    # # 

   # # # 

  # # # # 

 # # # # #

Giải pháp ->

Mã số.  

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
17

128. If you have a dictionary like this -> d1={“k1″. 10,”k2″. 20,”k3”. 30}. How would you increment values of all the keys ?

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
18

129. How can you get a random number in python?

Ans. To generate a random, we use a random module of python. Here are some examples To generate a floating-point number from 0-1

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
19

130. Explain how you can set up the Database in Django

All of the project’s settings, as well as database connection information, are contained in the settings. py file. Django works with the SQLite database by default, but it may be configured to operate with other databases as well

Database connectivity necessitates full connection information, including the database name, user credentials, hostname, and drive name, among other things

To connect to MySQL and establish a connection between the application and the database, use the django. db. backends. mysql driver.  

All connection information must be included in the settings file. Our project’s settings. py file has the following code for the database

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
20

This command will build tables for admin, auth, contenttypes, and sessions. You may now connect to the MySQL database by selecting it from the database drop-down menu.  

131. Give an example of how you can write a VIEW in Django?

The Django MVT Structure is incomplete without Django Views. A view function is a Python function that receives a Web request and delivers a Web response, according to the Django manual. This response might be a web page’s HTML content, a redirect, a 404 error, an XML document, an image, or anything else that a web browser can display

The HTML/CSS/JavaScript in your Template files is converted into what you see in your browser when you show a web page using Django views, which are part of the user interface. [Do not combine Django views with MVC views if you’ve used other MVC [Model-View-Controller] frameworks. ] In Django, the views are similar

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
21

132. Explain the use of sessions in the Django framework?

Django [and much of the Internet] uses sessions to track the “status” of a particular site and browser. Sessions allow you to save any amount of data per browser and make it available on the site each time the browser connects. The data elements of the session are then indicated by a “key”, which can be used to save and recover the data.  

Django uses a cookie with a single character ID to identify any browser and its website associated with the website. Session data is stored in the site’s database by default [this is safer than storing the data in a cookie, where it is more vulnerable to attackers]

Django allows you to store session data in a variety of locations [cache, files, “safe” cookies], but the default location is a solid and secure choice

Enabling sessions

When we built the skeleton website, sessions were enabled by default

The config is set up in the project file [locallibrary/locallibrary/settings. py] under the INSTALLED_APPS and MIDDLEWARE sections, as shown below

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
22

Using sessions

The request parameter gives you access to the view’s session property [an HttpRequest passed in as the first argument to the view]. The session id in the browser’s cookie for this site identifies the particular connection to the current user [or, to be more accurate, the connection to the current browser]

The session assets is a dictionary-like item that you can examine and write to as frequently as you need on your view, updating it as you go. Bạn có thể thực hiện tất cả các hành động từ điển tiêu chuẩn, chẳng hạn như xóa tất cả dữ liệu, kiểm tra sự hiện diện của khóa, lặp qua dữ liệu, v.v. Most of the time, though, you’ll merely obtain and set values using the usual “dictionary” API

The code segments below demonstrate how to obtain, change, and remove data linked with the current session using the key “my bike” [browser]

Note. One of the best things about Django is that you don’t have to worry about the mechanisms that you think are connecting the session to the current request. If we were to use the fragments below in our view, we’d know that the information about my_bike is associated only with the browser that sent the current request

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
23

A variety of different methods are available in the API, most of which are used to control the linked session cookie. There are ways to verify whether the client browser supports cookies, to set and check cookie expiration dates, and to delete expired sessions from the data store, for example. How to utilise sessions has further information on the whole API [Django docs]

133. List out the inheritance styles in Django

Abstract base classes. This inheritance pattern is used by developers when they want the parent class to keep data that they don’t want to type out for each child model

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
24

Two tables are formed in the database when we transfer these modifications. Chúng tôi có các trường tên, email, địa chỉ và điện thoại trong Bảng khách hàng. Chúng tôi có các trường cho tên, email, địa chỉ và chức vụ trong Bảng nhân viên. Table is not a base class that is built in This inheritance

Multi-table inheritance. It is utilised when you wish to subclass an existing model and have each of the subclasses have its own database table

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
25

Proxy models. This inheritance approach allows the user to change the behaviour at the basic level without changing the model’s field

This technique is used if you just want to change the model’s Python level behaviour and not the model’s fields. Ngoại trừ các trường, bạn kế thừa từ lớp cơ sở và có thể thêm các thuộc tính của riêng mình.  

  • Abstract classes should not be used as base classes
  • Multiple inheritance is not possible in proxy models

The main purpose of this is to replace the previous model’s key functions. It always uses overridden methods to query the original model

134. How can you get the Google cache age of any URL or web page?

Use the URL

//webcache.googleusercontent.com/search?q=cache:

Thí dụ

It contains a header like this

This is Google’s cache of https. //stackoverflow. com/. It’s a screenshot of the page as it looked at 11. 33. 38 GMT ngày 21 tháng 8 năm 2012. In the meanwhile, the current page may have changed

Tip. Use the find bar and press Ctrl+F or ⌘+F [Mac] to quickly find your search word on this page

You’ll have to scrape the resultant page, however the most current cache page may be found at this URL

http. //webcache. googleusercontent. com/search?q=cache. www. something. com/path

The first div in the body tag contains Google information

you can Use CachedPages website

Large enterprises with sophisticated web servers typically preserve and keep cached pages. Because such servers are often quite fast, a cached page can frequently be retrieved faster than the live website

  • A current copy of the page is generally kept by Google [1 to 15 days old]
  • Coral also retains a current copy, although it isn’t as up to date as Google’s
  • You may access several versions of a web page preserved over time using Archive. org

So, the next time you can’t access a website but still want to look at it, Google’s cache version could be a good option. First, determine whether or not age is important.  

135. Briefly explain about Python namespaces?

A namespace in python talks about the name that is assigned to each object in Python. Namespaces are preserved in python like a dictionary where the key of the dictionary is the namespace and value is the address of that object

Different types are as follows

  • Built-in-namespace – Namespaces containing all the built-in objects in python
  • Global namespace – Namespaces consisting of all the objects created when you call your main program
  • Enclosing namespace  – Namespaces at the higher lever
  • Local namespace – Namespaces within local functions

136. Briefly explain about Break, Pass and Continue statements in Python ? 

Break. When we use a break statement in a python code/program it immediately breaks/terminates the loop and the control flow is given back to the statement after the body of the loop

Continue. When we use a continue statement in a python code/program it immediately breaks/terminates the current iteration of the statement and also skips the rest of the program in the current iteration and controls flows to the next iteration of the loop

Pass. When we use a pass statement in a python code/program it fills up the empty spots in the program

Thí dụ

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
26

137. Give me an example on how you can convert a list to a string?

Below given example will show how to convert a list to a string. When we convert a list to a string we can make use of the “. join” function to do the same

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
27

apple orange mango papaya guava

138. Give me an example where you can convert a list to a tuple?

The below given example will show how to convert a list to a tuple. When we convert a list to a tuple we can make use of the function but do remember since tuples are immutable we cannot convert it back to a list.

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
28

[‘apple’, ‘orange’, ‘mango’, ‘papaya’, ‘guava’]

139. How do you count the occurrences of a particular element in the list ?

In the list data structure of python we count the number of occurrences of an element by using count[] function

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
29

Output. 1

140. How do you debug a python program?

There are several ways to debug a Python program

  • Using the
    y = 100
    
    def harshit_func[]:
    print [y]
    harshit_func[]
    print [y]
    
    40 statement to print out variables and intermediate results to the console
  • Using a debugger like
    y = 100
    
    def harshit_func[]:
    print [y]
    harshit_func[]
    print [y]
    
    41 or
    y = 100
    
    def harshit_func[]:
    print [y]
    harshit_func[]
    print [y]
    
    42
  • Adding
    y = 100
    
    def harshit_func[]:
    print [y]
    harshit_func[]
    print [y]
    
    43 statements to the code to check for certain conditions

141. What is the difference between a list and a tuple in Python?

A list is a mutable data type, meaning it can be modified after it is created. A tuple is immutable, meaning it cannot be modified after it is created. This makes tuples faster and safer than lists, as they cannot be modified by other parts of the code accidentally

142. Làm thế nào để bạn xử lý các ngoại lệ trong Python?

Các ngoại lệ trong Python có thể được xử lý bằng cách sử dụng khối

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
44–
y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
45. Ví dụ

y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
30

143. How do you reverse a string in Python?

There are several ways to reverse a string in Python

  • Using a slice with a step of -1
y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
31
  • Using the
    y = 100
    
    def harshit_func[]:
    print [y]
    harshit_func[]
    print [y]
    
    46 function
y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
32
  • Using a for loop
y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
33

144. How do you sort a list in Python?

There are several ways to sort a list in Python

  • Using the
    y = 100
    
    def harshit_func[]:
    print [y]
    harshit_func[]
    print [y]
    
    47 method
y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
34
  • Using the
    y = 100
    
    def harshit_func[]:
    print [y]
    harshit_func[]
    print [y]
    
    48 function
y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
35
  • Using the
    y = 100
    
    def harshit_func[]:
    print [y]
    harshit_func[]
    print [y]
    
    47 function from the
    y = 100
    
    def harshit_func[]:
    print [y]
    harshit_func[]
    print [y]
    
    50 module
y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
36

145. How do you create a dictionary in Python?

There are several ways to create a dictionary in Python

  • Using curly braces and colons to separate keys and values
y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
37
  • Using the
    y = 100
    
    def harshit_func[]:
    print [y]
    harshit_func[]
    print [y]
    
    51 function
y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
38
  • Using the
    y = 100
    
    def harshit_func[]:
    print [y]
    harshit_func[]
    print [y]
    
    51 constructor
y = 100

def harshit_func[]:
print [y]
harshit_func[]
print [y]
39

Python Interview-related FAQs

Ques 1. How do you stand out in a Python coding interview?

Now that you’re ready for a Python Interview in terms of technical skills, you must be wondering how to stand out from the crowd so that you’re the selected candidate. You must be able to show that you can write clean production codes and have knowledge about the libraries and tools required. If you’ve worked on any prior projects, then showcasing these projects in your interview will also help you stand out from the rest of the crowd

Also Read. Top Common Interview Questions

Ques 2. How do I prepare for a Python interview?

To prepare for a Python Interview, you must know syntax, keywords, functions and classes, data types, basic coding, and exception handling. Having a basic knowledge of all the libraries and IDEs used and reading blogs related to Python Tutorial will help you. Showcase your example projects, brush up on your basic skills about algorithms, and maybe take up a free course on python data structures tutorial. This will help you stay prepared

Ques 3. Are Python coding interviews very difficult?

The difficulty level of a Python Interview will vary depending on the role you are applying for, the company, their requirements, and your skill and knowledge/work experience. If you’re a beginner in the field and are not yet confident about your coding ability, you may feel that the interview is difficult. Being prepared and knowing what type of python interview questions to expect will help you prepare well and ace the interview

Ques 4. How do I pass the Python coding interview?

Having adequate knowledge regarding Object Relational Mapper [ORM] libraries, Django or Flask, unit testing and debugging skills, fundamental design principles behind a scalable application, Python packages such as NumPy, Scikit learn are extremely important for you to clear a coding interview. You can showcase your previous work experience or coding ability through projects, this acts as an added advantage

Also Read. How to build a Python Developers Resume

Ques 5. How do you debug a python program?

By using this command we can debug the program in the python terminal

$ python -m pdb python-script. py

Ques 6. Which courses or certifications can help boost knowledge in Python?

With this, we have reached the end of the blog on top Python Interview Questions. If you wish to upskill, taking up a certificate course will help you gain the required knowledge. You can take up a python programming course and kick-start your career in Python

How to study Python for interviews?

Python Coding Interviews. Tips & Best Practices .
Use enumerate[] to iterate over both indices and values
Debug problematic code with breakpoint[]
Format strings effectively with f-strings
Sort lists with custom arguments
Use generators instead of list comprehensions to conserve memory

What are the basic Python questions asked in interview?

Basic Python Interview Questions for Freshers .
What is Python? .
Python is an interpreted language. .
What is the difference between lists and tuples? .
What is pep 8? .
Các tính năng chính của Python là gì?.
How is Memory managed in Python? .
What is PYTHONPATH? .
What are Python Modules?

Is it easier to interview in Python?

Yes, in general, Python is useful to know and to use for coding interviews. One of Python's huge strengths over other languages, at least in the coding interview space, is that it's fairly easy to quickly mock up an algorithm for a question .

Chủ Đề