Trending questions in Python

+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
2,479 views
0 votes
1 answer

Examples for string find in Python

you can use str.index too: >>> 'sdfasdf'.index('cc') Traceback ...READ MORE

Aug 29, 2018 in Python by Priyaj
• 58,020 points
796 views
+2 votes
1 answer

How do you make a block comment in python?

''' This is a multiline comment. I ...READ MORE

Aug 23, 2018 in Python by Priyaj
• 58,020 points
966 views
0 votes
1 answer

How do I know what's going to be deleted?

An easy system would be to add ...READ MORE

Aug 28, 2018 in Python by anonymous
835 views
0 votes
1 answer

What's the canonical way to check for type in Python?

To check if o is an instance ...READ MORE

Aug 24, 2018 in Python by Priyaj
• 58,020 points
945 views
+1 vote
1 answer

Reading a large file, line by line in Python

The correct, fully Pythonic way to read ...READ MORE

Aug 21, 2018 in Python by Priyaj
• 58,020 points
1,027 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
1,097 views
+1 vote
1 answer

Accessing the index in 'for' loops?

Using an additional state variable, such as ...READ MORE

Aug 28, 2018 in Python by Priyaj
• 58,020 points
700 views
+1 vote
1 answer

Understanding Pickling in Python

While others have pointed to the Python ...READ MORE

Aug 22, 2018 in Python by Priyaj
• 58,020 points
935 views
0 votes
1 answer

What does eval() in Python do?

The eval function lets a Python program ...READ MORE

Aug 24, 2018 in Python by Priyaj
• 58,020 points
858 views
+1 vote
1 answer

Zip lists in Python

zip takes a bunch of lists likes a: ...READ MORE

Aug 22, 2018 in Python by Priyaj
• 58,020 points
859 views
+1 vote
2 answers

How to convert list to string

mylist = [1, 2, 3] ‘’.join(map(str, mylist)) ==> ...READ MORE

Aug 21, 2018 in Python by Omkar
• 69,220 points
1,012 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,020 points
1,076 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,460 points
1,192 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,020 points
2,260 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,020 points
1,796 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,020 points
1,007 views
0 votes
1 answer

Python variable declaration

Okay, first things first. There is no such ...READ MORE

Aug 27, 2018 in Python by Priyaj
• 58,020 points
566 views
0 votes
1 answer

How random.seed(): is used in python?

Pseudo-random number generators work by performing some ...READ MORE

Aug 24, 2018 in Python by Priyaj
• 58,020 points
687 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,460 points
1,048 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,020 points
664 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
1,965 views
+4 votes
8 answers

How can I use Python's range function?

The range function is mostly used in for-loop.  Ex: for ...READ MORE

Aug 21, 2018 in Python by Omkar
• 69,220 points
2,120 views
0 votes
1 answer

How to get text label from SAP using pywinauto[python]

Hi. Can you please tell me what ...READ MORE

Jun 28, 2018 in Python by Nietzsche's daemon
• 4,260 points
2,792 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
1,743 views
+2 votes
6 answers

Slicing in Python

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

Oct 18, 2018 in Python by abc
1,683 views
+1 vote
2 answers

Multiple line comment in Python

Try this ''' This is a multiline comment. ...READ MORE

Jul 31, 2018 in Python by Priyaj
• 58,020 points
1,142 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
1,684 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,020 points
1,138 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
1,741 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,510 points
1,164 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,020 points
1,052 views
+1 vote
2 answers

Static methods in Python?

Static methods are used when we need ...READ MORE

Aug 4, 2018 in Python by Ronaldobessmin
• 160 points

edited Aug 4, 2018 by Vardhan 968 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
• 69,220 points
1,698 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,020 points
545 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,020 points
1,064 views
+1 vote
1 answer

how to convert json to csv or to store in sql

You can convert JSON data to csv ...READ MORE

Jul 2, 2018 in Python by Nietzsche's daemon
• 4,260 points
2,296 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
• 69,220 points
1,054 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,510 points
677 views
0 votes
1 answer

ImportError: No module named requests

Requests is not available for use by ...READ MORE

Jun 26, 2018 in Python by Hamartia's Mask
• 1,580 points
2,536 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,020 points
1,200 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,020 points
974 views
+1 vote
1 answer

How to replace id with attribute corresponding to id of another table?

Use the following query statement and let ...READ MORE

Aug 8, 2018 in Python by Priyaj
• 58,020 points
2,476 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,020 points
862 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,510 points
555 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,020 points
858 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,020 points
637 views
+2 votes
4 answers

python 2d array

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

Oct 18, 2018 in Python by ritu
1,275 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,020 points
723 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
1,058 views