From 0f871e9b9ecdbb12beaede0c608f6bb8dbb4acb7 Mon Sep 17 00:00:00 2001 From: abregman Date: Fri, 20 Dec 2019 23:45:29 +0200 Subject: [PATCH] New Python questions --- README.md | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 26b79ae..e8097d4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ :information_source:  This repository contains questions on various DevOps and SRE related topics -:bar_chart:  There are currently **672** questions +:bar_chart:  There are currently **679** questions :books:  To learn more about DevOps check the resources in [DevOpsBit.com](https://devopsbit.com) @@ -1315,6 +1315,10 @@ To view all available signals run `kill -l` What kill 0 does?
+
+What kill -0 does?
+
+
What is a trap?
@@ -1645,7 +1649,7 @@ These system calls are reading the file /my/file and 5 is the file You found there is a server with high CPU load but you didn't find a process with high CPU. How is that possible?
-##### Network +##### Linux Networking
When you run ip a you see there is a device called 'lo'. What is it and why do we need it?
@@ -2530,6 +2534,20 @@ The immutable data types are: You can usually use the function hash() to check an object mutability, if it is hashable it is immutable, although this does not always work as intended as user defined objects might be mutable and hashable
+
+In Python, functions are first-class objects. What does it mean?
+ +In general, first class objects in programming languages are objects which can assigned to variable, used as a return value and can be used as arguments or parameters.
+In python you can treat functions this way. Let's say we have the following function + +``` +def my_function(): + return 5 +``` + +You can then assign a function to a variables like this `x = my_function` or you can return functions as return values like this `return my_function` +
+
What is PEP8? Give an example of 3 style guidelines
@@ -3026,8 +3044,45 @@ def sum(a, b): >>> None ``` +
- +
+How to improve the following block of code? + +``` +li = [] +for i in range(1,10): + li.append(i) +``` +
+
+ +
+You have the following function + +``` +def my_func(li = []): + li.append("hmm") + print(li) +``` + +If we call it 3 times, what would be the result each call? +
+
+ +
+Given the following function + +``` +def is_int(num): + if isinstance(num, int): + print('Yes') + else: + print('No') +``` +What would be the result of is_int(2) and is_int(False)? +
+
##### Data Structures & Types @@ -3045,6 +3100,10 @@ def sum(a, b): What is your experience with writing tests in Python?
+
+What assert does in Python?
+
+
Explain mocks
@@ -3053,6 +3112,10 @@ def sum(a, b): How do you measure execution time of small code snippets?
+
+Why one shouldn't use assert in non-test/production code?
+
+ ##### Flask