Most voted questions in Python

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,980 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,102 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
424 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
879 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
508 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
883 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
476 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,799 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
879 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
816 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
556 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
589 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
616 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
476 views
0 votes
2 answers

Indentation Error in Python

Use tabs instead of spaces. This is ...READ MORE

Feb 15, 2019 in Python by Shashank
• 1,370 points
697 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
758 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,295 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
680 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,551 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
518 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
561 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
650 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
584 views
0 votes
2 answers

How to use threading in Python?

 Thread is the smallest unit of processing that ...READ MORE

Apr 6, 2019 in Python by anonymous
1,072 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
433 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
737 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,742 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,576 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,050 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
454 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
759 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
831 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
483 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
538 views
0 votes
1 answer

Deleting a list element by index

Use the del() function del a[2] Or you can ...READ MORE

Jul 20, 2018 in Python by Nietzsche's daemon
• 4,260 points
507 views
0 votes
1 answer

Appending data to a file [closed]

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

Jul 20, 2018 in Python by Nietzsche's daemon
• 4,260 points
390 views
0 votes
1 answer

Connect to a MySQL DB in python?

db = MySQLdb.connect(host="localhost", # ...READ MORE

Jul 20, 2018 in Python by Nietzsche's daemon
• 4,260 points
562 views
0 votes
1 answer

Accessing Environment variables

import os print(os.environ['HOME']) READ MORE

Jul 20, 2018 in Python by Nietzsche's daemon
• 4,260 points
421 views
0 votes
1 answer

Random selections from list

Use random.choice() foo = ['a', 'b', 'c', 'd', ...READ MORE

Jul 20, 2018 in Python by Nietzsche's daemon
• 4,260 points
388 views
0 votes
1 answer

init.py file

It is used to denote directories on ...READ MORE

Jul 20, 2018 in Python by Nietzsche's daemon
• 4,260 points
398 views
0 votes
1 answer

__all__ in python

That is the list of public objects ...READ MORE

Jul 20, 2018 in Python by Nietzsche's daemon
• 4,260 points
707 views
0 votes
1 answer

Python Null Object

Use the 'None' keyword to denote the ...READ MORE

Jul 20, 2018 in Python by Nietzsche's daemon
• 4,260 points
683 views
0 votes
2 answers

Find the largest value in a dictionary

Use below running code which is simple ...READ MORE

Nov 25, 2021 in Python by Suhas
976 views
0 votes
3 answers

How to get the current time in Python

FOLLOWING WAY TO FIND CURRENT TIME IN ...READ MORE

Apr 8, 2019 in Python by rajesh
• 1,270 points
1,745 views
0 votes
1 answer

Python - convert string to list

try states.split() this would help. READ MORE

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

Best way to create a simple python web service

web.py is probably the simplest web framework ...READ MORE

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

What is the output of and explanation?

It will print concatenated lists. Output would ...READ MORE

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

*args and **kwargs in python

In cases when we don’t know how ...READ MORE

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

Monkey Patching

Dynamically modifying a class or module at ...READ MORE

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

Whenever you exit Python, is all memory de-allocated?

The answer here is no. The modules ...READ MORE

Jul 20, 2018 in Python by Priyaj
• 58,090 points
1,753 views