Wednesday, 22 January 2025

Python Coding Challange - Question With Answer(01220125)

 


Explanation

If you read through , which defines assignment expressions, you’ll see a section called

Exceptional cases, which has an example similar to the one in this quiz. They call this syntax

“Valid, though not recommended”.

That sums up this code well. You would not write an assignment expression like the one you see in

this code in your production code, and it’s terrible form.

It may help you understand how assignment expressions work.

A good way to figure out this quiz is to run it in smaller pieces. You can start by running the first

expression in your Python REPL:


1 >>> (a := 6, 9)

2 (6, 9)

3 >>> a

4 6

The REPL tells you that you constructed a tuple ((6, 9), which was immediately discarded), and

during the tuple creation the variable a was assigned the value 6.

Now run the second assignment expression in your REPL and inspect the variables:

1 >>> (a, b := 16, 19)

2 (6, 16, 19)

3 >>> a

4 6

5 >>> b

6 16

Output : 

a = 6 , b = 16

Once again we see a tuple was created, this time with the value from a, 16, and 19. The value 16 was

assigned to b by the walrus operator, and the 19 was discarded after being displayed.

0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (93) AI (37) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (184) C (77) C# (12) C++ (83) Course (67) Coursera (234) Cybersecurity (24) Data Analytics (2) data management (11) Data Science (135) Data Strucures (8) Deep Learning (21) Django (14) Downloads (3) edx (2) Engineering (14) Euron (22) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Generative AI (5) Google (34) Hadoop (3) HTML Quiz (1) HTML&CSS (47) IBM (30) IoT (1) IS (25) Java (93) Java quiz (1) Leet Code (4) Machine Learning (65) Meta (22) MICHIGAN (5) microsoft (4) Nvidia (4) Pandas (4) PHP (20) Projects (29) pyth (1) Python (961) Python Coding Challenge (406) Python Quiz (59) Python Tips (3) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (4) Software (17) SQL (42) UX Research (1) web application (8) Web development (4) web scraping (2)

Followers

Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses