You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+19-33Lines changed: 19 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ Bonus points for mentioning `enumerate` and use of `str.format`.
19
19
<b><a href="#">↥ back to top</a></b>
20
20
</div>
21
21
22
-
## Q. What is Python particularly good for? When is using Python the "right choice" for a project?
22
+
## Q. When is using Python the "right choice" for a project?
23
23
24
24
Python is a high-level, interpreted, interactive and object-oriented scripting language. Python is designed to be highly readable. It uses English keywords frequently where as other languages use punctuation, and it has fewer syntactical constructions than other languages.
25
25
@@ -34,17 +34,13 @@ Although likes and dislikes are highly personal, a developer who is "worth his o
34
34
- A dynamically-typed and strongly-typed language, offering the rare combination of code flexibility while at the same time avoiding pesky implicit-type-conversion bugs.
35
35
- It\'s free and open source! Need we say more?
36
36
37
-
With regard to the question of when using Python is the "right choice" for a project, the complete answer also depends on a number of issues orthogonal to the language itself, such as prior technology investment, skill set of the team, and so on. Although the question as stated above implies interest in a strictly technical answer, a developer who will raise these additional issues in an interview will always "score more points" with me since it indicates an awareness of, and sensitivity to, the "bigger picture" (i.e., beyond just the technology being employed). Conversely, a response that Python is always the right choice is a clear sign of an unsophisticated developer.
38
-
39
37
<divalign="right">
40
38
<b><a href="#">↥ back to top</a></b>
41
39
</div>
42
40
43
41
## Q. What are some drawbacks of the Python language?
44
42
45
-
For starters, if you know a language well, you know its drawbacks, so responses such as "there\'s nothing I don\'t like about it" or "it has no drawbacks" are very telling indeed.
46
-
47
-
The two most common valid answers to this question (by no means intended as an exhaustive list) are:
43
+
The two most common valid answers to this question are:
48
44
49
45
- The Global Interpreter Lock (GIL). CPython (the most common Python implementation) is not fully thread safe. In order to support multi-threaded Python programs, CPython provides a global lock that must be held by the current thread before it can safely access Python objects. As a result, no matter how many threads or processors are present, only one thread is ever being executed at any given time. In comparison, it is worth noting that the PyPy implementation discussed earlier in this article provides a stackless mode that supports micro-threads for massive concurrency.
50
46
- Execution speed. Python can be slower than compiled languages since it is interpreted. (Well, sort of. See our earlier discussion on this topic.)
@@ -73,19 +69,6 @@ So while it has problems, it is also a wonderful tool for a lot of things.
73
69
74
70
## Q. What are the key differences between Python 2 and 3?
75
71
76
-
```py
77
-
Division operator
78
-
`print` function
79
-
Unicode
80
-
xrange
81
-
Error Handling
82
-
`_future_` module
83
-
```
84
-
85
-
Although Python 2 is formally considered legacy at this point,its use is still widespread enough that is important for a developer to recognize the differences between Python 2 and 3.
86
-
87
-
- Here are some of the key differences that a developer should be aware of:
88
-
89
72
- Text and Data instead of Unicode and 8-bit strings. Python 3.0 uses the concepts of text and (binary) data instead of Unicode strings and 8-bit strings. The biggest ramification of this is that any attempt to mix text and data in Python 3.0 raises a TypeError (to combine the two safely, you must decode bytes or encode Unicode, but you need to know the proper encoding, e.g. UTF-8)
90
73
91
74
- This addresses a longstanding pitfall for naïve Python programmers. In Python 2, mixing Unicode and 8-bit data would work if the string happened to contain only 7-bit (ASCII) bytes, but you would get UnicodeDecodeError if it contained non-ASCII values. Moreover, the exception would happen at the combination point, not at the point at which the non-ASCII characters were put into the str object. This behavior was a common source of confusion and consternation for neophyte Python programmers.
@@ -162,13 +145,13 @@ div2(5.,2.)
162
145
163
146
Also, how would the answer differ in Python 3 (assuming, of course, that the above [print] statements were converted to Python 3 syntax)?
164
147
165
-
- kjalfkjaslf
148
+
- kjalfkjaslf
166
149
167
150
<divalign="right">
168
151
<b><a href="#">↥ back to top</a></b>
169
152
</div>
170
153
171
-
## Q. What is the difference between range and xrange? How has this changed over time?
154
+
## Q. What is the difference between range and xrange?
172
155
173
156
- As follows:
174
157
-`xrange` returns the xrange object while range returns the list, and uses the same memory and no matter what the range size is.
A module can find out its own module name by looking at the predefined global variable `__name__`. If this has the value `'__main__'`, the program is running as a script. Many modules that are usually used by importing them also provide a command-line interface or a self-test, and only execute this code after checking `__name__`:
236
220
237
221
```py
@@ -256,7 +240,7 @@ m = __import__(s)
256
240
257
241
## Q. How do I access a module written in Python from C?
258
242
259
-
You can get a pointer to the module object as follows:
243
+
You can get a pointer to the module object as follows:
260
244
261
245
`module = PyImport_ImportModule("");`
262
246
@@ -276,18 +260,18 @@ To convert, e.g., the number 144 to the string '144', use the built-in function
276
260
277
261
## Q. How is the Implementation of Python\'s dictionaries done?
278
262
279
-
Python dictionary needs to be declared first:
263
+
Python dictionary needs to be declared first:
280
264
`dict = {}`
281
265
282
-
Key value pair can be added as:
283
-
`dict[key] = value`
284
-
or
266
+
Key value pair can be added as:
267
+
`dict[key] = value`
268
+
or
285
269
`objDict.update({key:value})`
286
270
287
271
Remove element by:
288
272
`dict.pop(key)`
289
273
290
-
Remove all:
274
+
Remove all:
291
275
`objDict.clear()`
292
276
293
277
A hash value of the key is computed using a hash function, The hash value addresses a location in an array of "buckets" or "collision lists" which contains the (key , value) pair.
@@ -300,7 +284,7 @@ A hash value of the key is computed using a hash function, The hash value addres
300
284
301
285
"u" should be added before the string
302
286
303
-
`a = (u'Python')`
287
+
`a = (u'Python')`
304
288
`type(a) #will give you unicode`
305
289
306
290
Add unicode before the string. Ex: unicode(text) resulting in text.
@@ -364,7 +348,7 @@ Ans. In languages like C++, we have something like this:
364
348
365
349
But in Python, we do not have a switch-case statement. Here, you may write a switch function to use. Else, you may use a set of if-elif-else statements. To implement a function for this, we may use a dictionary.
366
350
367
-
```
351
+
```py
368
352
defswitch(choice):
369
353
switcher={
370
354
'Ram':'Monday',
@@ -482,7 +466,7 @@ Python has a private heap space to hold all objects and data structures. Being p
482
466
483
467
Objects referenced from the global namespaces of Python modules are not always deallocated when Python exits. This may happen if there are circular references. There are also certain bits of memory ...
484
468
485
-
## Q. Whenever you exit Python, is all memory de-allocated? State why is it so.
469
+
## Q. Whenever you exit Python, is all memory de-allocated?
486
470
487
471
The answer here is no. The modules with circular references to other objects, or to objects referenced from global namespaces, aren\'t always freed on exiting Python.
488
472
Plus, it is impossible to de-allocate portions of memory reserved by the C library.
@@ -506,7 +490,7 @@ disposition = cat[2]
506
490
507
491
Do this:
508
492
509
-
```
493
+
```js
510
494
cat = ['fat', 'orange', 'loud']
511
495
size, color, disposition = cat
512
496
```
@@ -805,7 +789,7 @@ Hi, monkey
805
789
<b><a href="#">↥ back to top</a></b>
806
790
</div>
807
791
808
-
## Q. Explain serialization and deserialization / Pickling and unpicking.
792
+
## Q. Explain serialization and deserialization / Pickling and unpicking?
809
793
810
794
Pickle module accepts any Python object and converts it into a string representation and dumps it into a file by using dump function, this process is called pickling. While the process of retrieving original Python objects from the stored string representation is called unpickling.
0 commit comments