Skip to main content
Stack Overflow
  1. About
  2. For Teams
Filter by
Sorted by
Tagged with
-5 votes
1 answer
135 views

I'm doing a simple task and my "solution" raised an error. I am using the walrus operator (:=) improperly but I would like to know how I can change my code to use it properly. Code basically ...
3 votes
5 answers
204 views

Is there a way to abuse assignment expressions or functional tools to generate the sequence x, f(x), f(f(x)), ... in one line? Here are some contrived examples to demonstrate: def iter(x, f, lim=10): ...
-4 votes
1 answer
132 views

Why are the negative k values being printed as the original value, but when we enter the positive realm, it gets strange? In: def j(k): for i in range(i:=k): i+=i print(i) for i in [-5,...
-3 votes
1 answer
163 views

I'm new to programming. I'm learning the walrus operator. I want the while loop end/stop when someone type quit or finish. Only quit works. when someone type "finish", it produces an output ...
2 votes
1 answer
98 views

I get: return r.group() if r := re.match(rx,l) else None ^ SyntaxError: invalid syntax whereas return r.group() if (r := re.match(rx,l)) else None is accepted. What ...
1 vote
2 answers
1k views

I read the documentation and lots of examples but do not fully understand how to use it. I have a function, screen() that returns a screenshot but may return None. I call this in a loop to a variable. ...
1 vote
2 answers
158 views

Take the following code: k = 'A' d = {} d[k := k.lower()] = 'b' print(k) print(d) This gives the output one would expect: a {'a': 'b'} However, for similar code in a project of mine, flake8 ...
0 votes
1 answer
77 views

Say we have this assignment statement: a = 5 Even though it'd obviously be ugly to do this for no reason, we could technically accomplish the same thing with: (a := 5) This still assigns 5 to a, and ...
-1 votes
1 answer
143 views

I have read up blogs and tutorials around the := operator but I am still trying to wrap my head around how to know when to use it. I understand its purpose is to improvement maintainability, avoiding ...
3 votes
1 answer
536 views

I was going to ask if there is a pylint-style code analyzer capable of suggesting the use of the := operator in places were it might improve the code. However, it looks like such test has been added ...
19 votes
2 answers
2k views

In Python (3.11) why does the use of an assignment expression (the "walrus operator") require wrapping in parentheses when used inside an f-string? For example: #!/usr/bin/env python from ...
0 votes
1 answer
102 views

Need to find the Fibonacci series up to N terms. n=int(input("Enter the n terms: ")) f_val=0 fib_list=[f_val:=f_val + i for i in range(n)] print(fib_list) While executing the above program, ...
3 votes
2 answers
315 views

In python you can write if (n := len(a)) > 10: print(f"List is too long ({n} elements, expected <= 10)") is there an equivalent feature in Julia?
-1 votes
1 answer
145 views

While making a function to manipulate the TypeVar from the typing module, I came across a problem. My function do work but I wanted to make it faster so I used the timeit module to test some different ...
-3 votes
1 answer
2k views

I see Python examples with := and ::=. I've got a good understanding of the walrus operator from an article on RealPython(The Walrus Operator: Python 3.8 Assignment Expressions). I also went through ...

15 30 50 per page
1
2 3 4 5 6

AltStyle によって変換されたページ (->オリジナル) /