Trending questions in Python

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
• 56,200 points
110 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
• 56,200 points
20 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
• 56,200 points
20 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,320 points
53 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,320 points
35 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
• 56,200 points
40 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
• 56,200 points
40 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
• 56,200 points
21 views
+1 vote
2 answers

Appending data to a file

First open the file that you want ...READ MORE

Jul 23, 2018 in Python by Omkar
• 67,290 points
27 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
• 56,200 points
265 views
0 votes
2 answers

Splitting a Python String

The split() method in Python returns a ...READ MORE

Oct 3, 2018 in Python by anonymous
57 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
• 56,200 points
31 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
• 56,200 points
67 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
• 56,200 points
19 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
• 56,200 points
61 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
• 56,200 points
40 views
+1 vote
1 answer

Appending data to a file [closed]

To append a file without overwriting, open ...READ MORE

Aug 7, 2018 in Python by Omkar
• 67,290 points

edited Aug 7, 2018 by Omkar 31 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
• 56,200 points
30 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
• 56,200 points
21 views
+1 vote
4 answers

Count the frequency of an item in a python list

To count the number of appearances: from collections ...READ MORE

Oct 18, 2018 in Python by tinitales
323 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
• 56,200 points
80 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
• 56,200 points
37 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
• 56,200 points
24 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
• 56,200 points
18 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 Anmol
• 3,620 points
54 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,810 points
78 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
• 56,200 points
26 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
• 56,200 points
8 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,810 points
43 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,810 points
36 views
+2 votes
6 answers

How can I change directory or "cd" in Python?

Context Manager: cd import os class cd:     """Context manager for ...READ MORE

Oct 18, 2018 in Python by Nabarupa
86 views
+4 votes
6 answers

Does Python have a ternary conditional operator like C does?

Yes, the syntax is: a if condition else ...READ MORE

Apr 13, 2018 in Python by Nietzsche's daemon
• 4,260 points
113 views
+2 votes
4 answers

python 2d array

You should make a list of lists, ...READ MORE

Oct 18, 2018 in Python by ritu
93 views
+2 votes
6 answers

Slicing in Python

Index: ------------> ...READ MORE

Oct 18, 2018 in Python by abc
53 views
+1 vote
5 answers

convert string to int python

Using list comprehensions: t2 = [map(int, list(l)) for ...READ MORE

Oct 18, 2018 in Python by donald
62 views
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

Apr 11, 2018 in Python by hemant
• 5,750 points
119 views
+1 vote
5 answers

Check whether the file exists or not?

Use this import os os.path.exists(path) # Returns whether the ...READ MORE

Oct 18, 2018 in Python by reyam
79 views
0 votes
1 answer

Printing a large numpy array

numpy.set_printoptions(threshold='nan') READ MORE

Jul 20, 2018 in Python by Nietzsche's daemon
• 4,260 points
94 views
+1 vote
4 answers

Comparing input functions

In Python raw_input() allows you to enter ...READ MORE

Oct 18, 2018 in Python by fuji
35 views
+1 vote
4 answers

How can I concatenate str and int objects?

If you want to concatenate int or ...READ MORE

Oct 18, 2018 in Python by subhm
41 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
• 56,200 points
59 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
48 views
0 votes
1 answer

Mean and average in numpy

np.average() can be used to calculate weighted ...READ MORE

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

Find the largest value in a dictionary

import operator stats = {'a':1000, 'b':3000, 'c': 100} max(stats.iteritems(), ...READ MORE

Jul 20, 2018 in Python by Nietzsche's daemon
• 4,260 points
41 views
+4 votes
6 answers

Use of "continue" in python

The break statement is used to "break" ...READ MORE

Jul 16, 2018 in Python by Omkar
• 67,290 points
125 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
30 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
29 views
0 votes
1 answer

Monkey Patching

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

Jul 20, 2018 in Python by Priyaj
• 56,200 points
34 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
26 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
25 views