warning: "statement seems to have no effect" [closed] - python

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
PyCharm is highlighting my code in yellow and giving a warning. On hover, it says:
statement seems to have no effect
Can somebody please explain what this means?

You need a single equals sign = to assign a value to punctuacion:
punctuacion = punctuacion + 10
In this case, it'd be even better to use a compound assignment operator, like `punctuation
punctuacion += 10
As is, the == is the equality operator, which just evaluates to an unused value (either True or False). That's useless, hence the warning, the IDE suspects you made a mistake like this.

Related

'input' is not defined Pylance(reportUndefinedVariable) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 months ago.
Improve this question
it just started happening, now all "input()" gets yellow underline
But code works properly
a=int(input())
if u r keeping any integer values.
This problem does not occur in my pylance.
It seems that there are some errors in your vscode's pylance. It doesn't recognize the input() method.
You can try to update the pylance in the extension store or add the following code in settings.json:
"python.analysis.diagnosticSeverityOverrides": {
"reportUndefinedVariable": "none"
}
That happens because you are using input. Use raw_input instead. raw_input is what you have to use with python 2.

Can both os.DirEntry.is_dir() and os.DirEntry.is_file() return False for an object in os.scandir()? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am making an event handler similar to os.system("dir") and it would be nice to know. I'm not sure what the object could be, but I wanted to be sure.
Yes it's possible for both os.DirEntry.is_dir and os.DirEntry.is_file to return False: is_dir() is for directories (which is obvious) but is_file() is only for so-called regular files.
This means it can return False for something which is not a directory, like devices, pipes, ... for instance on unices most of /dev is neither a file nor a directory. I'm less sure about windows, but it probably has such concepts e.g. the "magic" reserved names like CON or PRN or LPT1 (though I guess those wouldn't show up in a scandir).

Python String Expression format [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am not understanding the meaning of each of the terms in the curly brackets (I was a bit overwhelmed with this source https://docs.python.org/3.4/library/string.html)
def format_money(amount):
return '${:.2f}'.format(amount)
I know that it return this format: $39.99 but I don't know what each sign means. Could someone explain?
the $ is outside of formatted string placeholder
{: is the beginning of the formatted string
.2f is the fixed number of places after the decimal
} end of your place holder
i find it always fun to experiment to test a function or a module, you can also format the date, output, lots of other stuff... all in that lovely reference page

How do I execute code that is taken as user input? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Is there a way to actually take a well formatted input and execute it at an appropriate time?
Something like:
num = 5
command = input()
# do something with command
Now, if i enter "print(num)" as input, it should output
5
What you suggest actually works as is:
>>> x=1
>>> eval(input())
print(x)
1
Another method you can have a look at is the exec method (and above that is a detailed description for eval).
Depending on what you are going for this might be a bad idea though. Have a look at the local and global parameters to restrict the environment.

Why is Python strict about indentation? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
This question is coming from this Stack Overflow question. Why is Python is designed to use correct indentation either space or tab? In this way, is it purposefully to serve any benefit?
Indentation is essential in Python; it replaces curly braces, semi-colons, etc. in C-like syntax.
Consider this code snippet, for example:
def f(x):
if x == 0:
print("x is zero")
print("where am i?")
If it weren't for indentation, we would have no way of indicating what code block the second print statement belongs to. Is it under the if statement, the function f or just by itself in the document?
There is no set width of a tab character, so Python has no way of knowing how many spaces to count a tab as.

Categories