Skip to content

Commit e3b96fa

Browse files
committed
Update README.md
1 parent ab03b91 commit e3b96fa

File tree

1 file changed

+19
-33
lines changed

1 file changed

+19
-33
lines changed

README.md

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Bonus points for mentioning `enumerate` and use of `str.format`.
1919
<b><a href="#">↥ back to top</a></b>
2020
</div>
2121

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?
2323

2424
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.
2525

@@ -34,17 +34,13 @@ Although likes and dislikes are highly personal, a developer who is "worth his o
3434
- 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.
3535
- It\'s free and open source! Need we say more?
3636

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-
3937
<div align="right">
4038
<b><a href="#">↥ back to top</a></b>
4139
</div>
4240

4341
## Q. What are some drawbacks of the Python language?
4442

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:
4844

4945
- 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.
5046
- 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.
7369

7470
## Q. What are the key differences between Python 2 and 3?
7571

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-
8972
- 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)
9073

9174
- 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.)
162145

163146
Also, how would the answer differ in Python 3 (assuming, of course, that the above [print] statements were converted to Python 3 syntax)?
164147

165-
- kjalfkjaslf
148+
- kjalfkjaslf
166149

167150
<div align="right">
168151
<b><a href="#">↥ back to top</a></b>
169152
</div>
170153

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?
172155

173156
- As follows:
174157
- `xrange` returns the xrange object while range returns the list, and uses the same memory and no matter what the range size is.
@@ -232,6 +215,7 @@ Example: BaseAlias = class Derived(BaseAlias): def meth(self): BaseAlias.meth(se
232215
</div>
233216

234217
## Q. How do I find the current module name?
218+
235219
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__`:
236220

237221
```py
@@ -256,7 +240,7 @@ m = __import__(s)
256240

257241
## Q. How do I access a module written in Python from C?
258242

259-
You can get a pointer to the module object as follows:
243+
You can get a pointer to the module object as follows:
260244

261245
`module = PyImport_ImportModule("");`
262246

@@ -276,18 +260,18 @@ To convert, e.g., the number 144 to the string '144', use the built-in function
276260

277261
## Q. How is the Implementation of Python\'s dictionaries done?
278262

279-
Python dictionary needs to be declared first:
263+
Python dictionary needs to be declared first:
280264
`dict = {}`
281265

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
285269
`objDict.update({key:value})`
286270

287271
Remove element by:
288272
`dict.pop(key)`
289273

290-
Remove all:
274+
Remove all:
291275
`objDict.clear()`
292276

293277
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
300284

301285
"u" should be added before the string
302286

303-
`a = (u'Python')`
287+
`a = (u'Python')`
304288
`type(a) #will give you unicode`
305289

306290
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:
364348

365349
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.
366350

367-
```
351+
```py
368352
def switch(choice):
369353
switcher={
370354
'Ram':'Monday',
@@ -482,7 +466,7 @@ Python has a private heap space to hold all objects and data structures. Being p
482466

483467
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 ...
484468

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?
486470

487471
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.
488472
Plus, it is impossible to de-allocate portions of memory reserved by the C library.
@@ -506,7 +490,7 @@ disposition = cat[2]
506490

507491
Do this:
508492

509-
```
493+
```js
510494
cat = ['fat', 'orange', 'loud']
511495
size, color, disposition = cat
512496
```
@@ -805,7 +789,7 @@ Hi, monkey
805789
<b><a href="#">↥ back to top</a></b>
806790
</div>
807791

808-
## Q. Explain serialization and deserialization / Pickling and unpicking.
792+
## Q. Explain serialization and deserialization / Pickling and unpicking?
809793

810794
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.
811795

@@ -824,6 +808,7 @@ print(pickle.loads(pickled_string))
824808
```
825809

826810
Reference:
811+
827812
[1] https://www.sanfoundry.com/python-questions-answers-pickle-module/
828813
[2] https://docs.python-guide.org/scenarios/serialization/
829814

@@ -1006,7 +991,8 @@ print(b)
1006991
```
1007992

1008993
Output:
1009-
```
994+
995+
```py
1010996
M m1 of X
1011997
In m2 of Y
1012998
2337815

0 commit comments

Comments
 (0)