From the course: Python for JavaScript Developers
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Solution: Port the code - Python Tutorial
From the course: Python for JavaScript Developers
Solution: Port the code
(upbeat music) - [Instructor] So, how did it go? Our challenge for this video was to port a small JavaScript program into Python. And kind of paying attention to conventions is always a good idea. So here I begin by importing decimal from the Decimal module. And this enables me to get that precise decimal type we talked about. And then on line three, I use all caps in order to indicate that this is a constant. For all three of these, I actually use all caps if you notice because I don't change these definitions in the runtime. So basically we have user name. Then we have credits. Then we have items in cart. And in line four for credits, you'll see me using the decimal type. Then in line seven, we have get first item, which takes a user, credits, items, and returns that interpolated string. So it interpolates the items zero and user and credits. It uses that F string syntax we talked about. Finally, in line 10…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Why style is crucial5m 44s
-
(Locked)
Numbers, numeric types, and decimals4m 58s
-
(Locked)
Migrating from arrays to Python lists, tuples, and dictionaries8m 20s
-
(Locked)
Strings and formatting: Python vs. JavaScript3m 38s
-
(Locked)
Python slices4m 11s
-
(Locked)
Challenge: Port the code1m 17s
-
(Locked)
Solution: Port the code1m 43s
-
-
-
-
-