Most answered questions in Python

0 votes
1 answer

How to install Python MySQLdb module using pip?

It's easy to do, but hard to ...READ MORE

Aug 20, 2018 in Python by charlie_brown
• 7,720 points
1,776 views
0 votes
1 answer

Pointers in Python?

I want form.data['field'] and form.field.value to always have the same value This ...READ MORE

Aug 20, 2018 in Python by charlie_brown
• 7,720 points
914 views
+1 vote
1 answer

How do I trim whitespace?

Whitespace on both sides: s = " \t ...READ MORE

Aug 20, 2018 in Python by Priyaj
• 58,090 points
474 views
+1 vote
1 answer

How to check if a string is null in python

Try this: if cookie and not cookie.isspace(): # the ...READ MORE

Aug 20, 2018 in Python by Priyaj
• 58,090 points
22,732 views
0 votes
1 answer

Creating an empty list in Python

Here is how you can test which ...READ MORE

Aug 17, 2018 in Python by Priyaj
• 58,090 points
911 views
0 votes
1 answer

Python string formatting: % vs. .format

To answer your first question... .format just ...READ MORE

Aug 17, 2018 in Python by Priyaj
• 58,090 points
762 views
0 votes
1 answer

How do you create nested dict in Python?

It is important to remember when using ...READ MORE

Aug 16, 2018 in Python by Priyaj
• 58,090 points
3,269 views
0 votes
1 answer

How can I check for NaN in Python?

math.isnan() Checks if the float x is a ...READ MORE

Aug 16, 2018 in Python by Priyaj
• 58,090 points
23,845 views
+1 vote
1 answer

How to append an integer to a string?

You can not directly concatenate two different ...READ MORE

Aug 16, 2018 in Python by Omkar
• 69,230 points
1,257 views
0 votes
1 answer

Python using basicConfig method to log to console and file

I can't reproduce it on Python 3.3. ...READ MORE

Aug 14, 2018 in Python by aryya
• 7,450 points
904 views
0 votes
1 answer

How do you express binary literals in Python?

For reference—future Python possibilities: Starting with Python 2.6 you ...READ MORE

Aug 14, 2018 in Python by aryya
• 7,450 points
751 views
0 votes
1 answer

Add new keys to a dictionary?

>>> d = {'key':'value'} >>> print(d) {'key': ...READ MORE

Aug 13, 2018 in Python by Priyaj
• 58,090 points
389 views
0 votes
1 answer

'Syntax Error: invalid syntax' for no apparent reason

You're missing a close paren in this ...READ MORE

Aug 13, 2018 in Python by Priyaj
• 58,090 points
2,248 views
0 votes
1 answer

How do you get the logical xor of two variables in Python?

What i found is that you can use ...READ MORE

Aug 10, 2018 in Python by Priyaj
• 58,090 points
11,367 views
0 votes
1 answer

What is the difference between re.search and re.match?

The theoritical approach can be this way, re.match is ...READ MORE

Aug 10, 2018 in Python by Priyaj
• 58,090 points
11,490 views
0 votes
1 answer

A basic question about “while true”

while True means loop forever. The while ...READ MORE

Aug 8, 2018 in Python by bug_seeker
• 15,520 points
502 views
0 votes
1 answer

How to read/process command line arguments?

The canonical solution in the standard library ...READ MORE

Aug 8, 2018 in Python by bug_seeker
• 15,520 points
378 views
0 votes
1 answer

Difference between append vs. extend list methods in Python

append: Appends object at the end. x = ...READ MORE

Aug 8, 2018 in Python by bug_seeker
• 15,520 points
1,997 views
0 votes
1 answer

Why there is no do while loop in python

There is no do...while loop because there ...READ MORE

Aug 6, 2018 in Python by Priyaj
• 58,090 points
7,123 views
0 votes
1 answer

What are the differences between type() and is instance()?

Normally, in Python, you want your code ...READ MORE

Aug 6, 2018 in Python by Priyaj
• 58,090 points
426 views
0 votes
1 answer

How to use string.replace() in python 3.x

replace() is a method of <class 'str'> ...READ MORE

Aug 3, 2018 in Python by Priyaj
• 58,090 points
890 views
0 votes
1 answer

What is the purpose of self?

The reason you need to use self. ...READ MORE

Aug 3, 2018 in Python by Priyaj
• 58,090 points
513 views
0 votes
1 answer

Correct way to write line to file?

This should be as simple as: with open('somefile.txt', ...READ MORE

Aug 3, 2018 in Python by Priyaj
• 58,090 points
887 views
0 votes
1 answer

Python: list of lists

Lists are a mutable type - in ...READ MORE

Aug 2, 2018 in Python by bug_seeker
• 15,520 points
483 views
0 votes
1 answer

Create an empty list in python with certain size

Try this instead: lst = [None] * 10 The ...READ MORE

Aug 2, 2018 in Python by bug_seeker
• 15,520 points
27,812 views
0 votes
1 answer

When to use %r instead of %s in Python? [duplicate]

The %s specifier converts the object using ...READ MORE

Aug 2, 2018 in Python by bug_seeker
• 15,520 points
890 views
0 votes
1 answer

Difference between del, remove and pop on lists

es, remove removes the first matching value, ...READ MORE

Aug 1, 2018 in Python by Priyaj
• 58,090 points
822 views
0 votes
1 answer

Python 'If not' syntax

Yes, if bar is not None is ...READ MORE

Aug 1, 2018 in Python by Priyaj
• 58,090 points
561 views
0 votes
1 answer

Reverse a string in Python

How about: >>> 'hello world'[::-1] 'dlrow olleh' This is ...READ MORE

Aug 1, 2018 in Python by Priyaj
• 58,090 points
599 views
0 votes
1 answer

Is there a label/goto in Python?

No, Python does not support labels and ...READ MORE

Aug 1, 2018 in Python by Priyaj
• 58,090 points
630 views
0 votes
1 answer

Understanding the map function

map isn't particularly pythonic. I would recommend ...READ MORE

Jul 31, 2018 in Python by Priyaj
• 58,090 points
482 views
0 votes
1 answer

How do I copy a file in python?

Use the shutil module. copyfile(src, dst) Copy the contents ...READ MORE

Jul 31, 2018 in Python by Priyaj
• 58,090 points
773 views
0 votes
1 answer

How to exit from Python without traceback?

Perhaps you're trying to catch all exceptions ...READ MORE

Jul 31, 2018 in Python by Priyaj
• 58,090 points
5,304 views
0 votes
1 answer

How to split a string into a list?

You can use the function  text.split() This should be ...READ MORE

Jul 30, 2018 in Python by Priyaj
• 58,090 points
692 views
0 votes
1 answer

What does if __name__ == “__main__”: do?

According to what I know,  When the Python ...READ MORE

Jul 30, 2018 in Python by Priyaj
• 58,090 points
1,555 views
0 votes
1 answer

How to use “raise” keyword in Python

You can use it to raise errors ...READ MORE

Jul 30, 2018 in Python by Priyaj
• 58,090 points
526 views
0 votes
1 answer

How do I sort a dictionary by value?

It is not possible to sort a ...READ MORE

Jul 30, 2018 in Python by Priyaj
• 58,090 points
565 views
0 votes
1 answer

Python join: why is it string.join(list) instead of list.join(string)?

This is because join is a "string" ...READ MORE

Jul 30, 2018 in Python by Priyaj
• 58,090 points
653 views
0 votes
1 answer

How to sort a list of strings?

Try  items = ["live", "like", "code", "cool", "bug"] ...READ MORE

Jul 27, 2018 in Python by Priyaj
• 58,090 points
589 views
0 votes
1 answer

How do you append to a file?

with open("test.txt", "a") as myfile: myfile.write("appended text ...READ MORE

Jul 27, 2018 in Python by Priyaj
• 58,090 points
437 views
0 votes
1 answer

How to import other Python files?

importlib is recent addition in Python to ...READ MORE

Jul 27, 2018 in Python by Priyaj
• 58,090 points
742 views
0 votes
1 answer

What is the difference between Python and IPython?

There are few differences between Python and ...READ MORE

Jul 26, 2018 in Python by Priyaj
• 58,090 points
3,757 views
0 votes
1 answer

Behaviour of increment and decrement operators in Python

When you want to increment or decrement, ...READ MORE

Jul 26, 2018 in Python by Priyaj
• 58,090 points
3,586 views
0 votes
1 answer

Generate random integers between 0 and 9

Try: from random import randint print(randint(0, 9)) More info: ...READ MORE

Jul 26, 2018 in Python by Priyaj
• 58,090 points
1,053 views
0 votes
1 answer

How to properly ignore Exceptions?

try:  doSomething() except:  pass or try:  doSomething() except Exception: ...READ MORE

Jul 26, 2018 in Python by Priyaj
• 58,090 points
459 views
0 votes
1 answer

What is the Python equivalent for a case/switch statement?

if x == 'a':  # Do the ...READ MORE

Jul 26, 2018 in Python by Priyaj
• 58,090 points
768 views
0 votes
1 answer

How to add to the python path in Windows?

You know what has worked for me ...READ MORE

Jul 25, 2018 in Python by Frankie
• 9,830 points
839 views
0 votes
1 answer

Python - convert string to list

states.split() will return ['Alaska', 'Alabama', 'Arkansas', 'American', 'Samoa', ...READ MORE

Jul 25, 2018 in Python by Frankie
• 9,830 points
490 views
0 votes
1 answer

How to get the current time in Python

>>> import datetime >>> datetime.datetime.now() datetime(2018, 25, ...READ MORE

Jul 25, 2018 in Python by Frankie
• 9,830 points
545 views
+1 vote
1 answer

What is the correct order to learn concepts in Python for machine learning?

Machine Learning is a vast domain. It ...READ MORE

Jul 25, 2018 in Python by Abhi
• 3,720 points
809 views