Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
2 answers
93 views

Why is the nonlocal assignment of this variable not considered a previous binding?

spam is assigned as nonlocal in the do_nonlocal() function, which, according to the Python docs, changes scope_test's binding of spam. But the docs also state that there was no previous binding for ...
maltuin's user avatar
  • 11
-1 votes
2 answers
120 views

I can't access to the var from a for loop if it inside an if statement that is in the same scope

I need some help in my project. the problem is that I can't access to the variable from a for loop, the variable is inside a if statement that is in the same scope. Here is an example: import os ...
TWISTER_FROSTE's user avatar
0 votes
1 answer
24 views

Accessing variables in the local scope of a python decorator [duplicate]

Consider: def g(value): def f(): return value return f x = g(3) x() # prints 3 Given x in the example, the returned closure from g(3), is there any way to inspect that is the value ...
Jim's user avatar
  • 801
-1 votes
1 answer
73 views

May i know why the below code is not errored out, even though function returning address of a local variable [duplicate]

Cpp Code: #include <iostream> using namespace std; int* scopeProblem() { int *bret; int b=10; bret =&b; return bret; } int main() { cout<<*(scopeProblem()); ...
roney km's user avatar
0 votes
3 answers
145 views

Having trouble figuring out params, arguments, passing variables to functions in Python

I understand this conceptually, but I can't seem to wrap my head around the syntax. Here is specifically what I'm working on - getting an average rating, from 5 inputs, and displaying an amount of ...
r00's user avatar
  • 65
0 votes
1 answer
850 views

cannot access global variable after trying to modify it inside a function [duplicate]

I encounter no problems running this code: x = 1 def func(): print(x + 1) func() 2 But when I run this: x = 1 def func(): try: x += 1 except: pass print(x + 1) ...
UpTheIrons's user avatar
-1 votes
1 answer
62 views

Why can we declare multiple identically named variables globally but not locally in C? [duplicate]

When I declare a global variable multiple times, I do not get any error. #include <stdio.h> int i; int i; int main() { printf("%d",i); } But if I declare a local variable ...
veerraju annamdevula's user avatar
1 vote
1 answer
244 views

Are variables used in nested functions considered global?

This is a dumb question, so I apologise if so. This is for Julia, but I guess the question is not language specific. There is advice in Julia that global variables should not be used in functions, but ...
user avatar
0 votes
1 answer
110 views

How does the compiler not confuse local variable named size with function call size()?

While reading a C++ textbook, I came across this specific piece of code: vector<double> homework; typedef vector<double>::size_type vec_sz; vec_sz size = homework.size(); I wonder how isn'...
gigis95's user avatar
  • 66
0 votes
0 answers
21 views

Scope of length of a given list [duplicate]

I'm learning about scopes of python variables: global, local, nonlocal, and built-in. And I'm having trouble with identifying the scope of following variable(var_5) in each line (1,2,3 7 4). list = [1,...
Indi's user avatar
  • 429
0 votes
1 answer
1k views

Name is used in an enclosing local scope to define a local or parameter

I'm trying to test a small piece of code in a totally separate mini project and isolated just this piece, but am getting the following error: error CS0136: A local or parameter named 'phoneNumber' ...
Jumble_Socks's user avatar
0 votes
0 answers
105 views

Why does locals()['var_name'] = value affect the actual local namespace?

def f(): s = 'foo' loc = locals() loc['s'] = 'bar' print(s) loc['z'] = 'baz' print(locals()) f() I understand that the locals function returns a copy of the local namespace....
NKUwakwe's user avatar
0 votes
1 answer
341 views

Global variable priority over local variable when global function called in scope of local variable c++

I just wanted to clarify a gap in my knowledge. Given the following code: I would have expected that "Hi" is printed, based purely on the fact that in the scope of foo, the definition of ...
cheeseburgereddy's user avatar
1 vote
1 answer
307 views

what is difference between scope and namespace in javascript

hi everyone . actually I'm newly learning Javascript . I read about scopes in javascript . then I read somewhere about namespace in Js and i was wondered if namespace is exactly the same as scope , so ...
Mahdi zarepoor's user avatar
0 votes
2 answers
491 views

why static local variable doesn't preserve it's value in this case?

First take a look: #include <stdio.h> static int v1 = 0; int fun() { static int v2 = 0; ++v2 && ++v1; printf("%i\n", v2); return v2; } int main() { ++v1; ...
Question's user avatar

15 30 50 per page
1
2 3 4 5