Moving from simple command-line scripts to web app development is a big leap in our Python journey. There are a variety of framework options with; however, even the concept can be overwhelming if you’ve never worked with a web framework.
If you’ve found this article then you’re probably researching different Python frameworks and trying to decide which to invest in. Instead of suffering from analysis paralysis, take a leap of faith and jump into Flask with this guide.
The first step is the hardest to take, but the easiest to make .We’ll …
It’s natural to focus — and get stuck on — syntax, structures, and libraries when learning a new programming language. Especially if it’s your first language, learning how to manage an environment is normally filed away under blissful ignorance.
It’s possible (somewhat) to get quite far without tackling environment management, but once you hit a wall that requires it, you’ll be left looking at a disorganized system folder that can best be described as a cluster****.
To start building good habits early, introduce Python virtual environments. …
Node.js as a JS runtime environment has become an absolute backbone for technology stacks. Any time you see the letter “N” in a tech stack, such as MEAN, that’s most likely Node.
With great success comes longevity and with longevity comes legacy challenges, some of which are too deeply ingrained in the architecture to be addressed.
There are a variety of reasons to count backwards in a program. Maybe you want to iterate over a list starting from the end or simply want to display a countdown timer.
We have multiple options available to us and are going to introduce two of those options: manually modifying a counter variable and using the
The most basic method of counting backwards is to use a counting variable inside of a while loop. We need three definitions in order to count backwards: the starting point, how to exit the loop, and how to modify the loop.
Let’s set up a countdown timer from 10 to 0. We identify that the counter starts at 10, exits at 0, and the counter will be reduced by one after each loop. …
Create a function that converts a list to a two-dimensional “list of lists” where each nested structure is a specified equal length.
Here are some example inputs and expected outputs:
# INPUT LIST: [1,2,3,4,5,6]
# INPUT SIZE: 3
# OUTPUT: [[1,2,3],[4,5,6]]# INPUT LIST: [1,2,3,4,5]
# INPUT SIZE: 2
# OUTPUT: [[1,2],[3,4],]# INPUT LIST: [1,2,3]
# INPUT SIZE: 4
# OUTPUT: [[1,2,3]]
Reviewing our examples, there are some important distinctions for scenarios where the list and chunk size do not perfect match up.
Python provides a native library for passing command-line values to scripts called argparse. With argparse, we can include variable values in the execution command instead of using input() to request the value mid-execution. This saves us time and more importantly allows script execution lines to be saved and conveniently used — either manually or automated.
Whenever teaching programming, the analogy I use for copying a list is taking a photocopy. It’s a simple, visual example that everybody can relate to. But more importantly, the analogy has a major flaw — intentionally. Unlike a photocopy, there is an additional component to copying lists and any other complex data structure: shallow copying vs deep copying.
In this guide we’ll demonstrate both shallow and deep copying to highlight the difference. Shallow copying is a simpler process so we’ll provide three different techniques for doing so.
We’re going to need some initial starter code to get started. We’re defining a simple class with one attribute
__init__ method is executed when an instance of the class is created and the
__repr__ method is responsible for defining when an instance of the class is printed. …
The last 24 months have been an interesting time. Filled with change, I’ve moved from Training to Professional Services, which has been redefined as Customer Success. I have one directive: make the customer successful. Hold my drink…
Pursuing this simple yet difficult goal, I find myself asking the same question over and over. Do I fish for the man or do I teach the man to fish? Well duh, dummy you teach them to fish. Except it’s not that easy because customers don’t want the small fish, they’re looking for whales.
Listening to Pulse 2018’s Great Debate: How Technical Should CSMs Be? I realized the answer, as any debate should illuminate, is somewhere in the middle. I’m fortunate to have complimentary skillsets — I’m not one-dimensional. …
One of the first eye-blinking, brow furrowing experiences when learning Python is an inevitable floating point inaccuracy. We’d expect a computer to be precise and “get math right,” but it’s not so simple.
Let’s try and add 0.1 together three times and demonstrate the problem.
total = 0.1 + 0.1 + 0.1
print(total) # 0.30000000000000004
To make sense of this, we need to understand (and accept) that floating point arithmetic is used to store decimal values.
Without getting too deep, the takeaway is that Python uses formulas to store decimals and this leads to occasional inaccuracies.
The same discrepancy comes up when we try to manually add our values in a loop or use the
sum() function. …
Refactoring is the process of updating existing code while functionally remain the same. There are a variety of reasons for refactoring code including performance, readability, and future scalability.
Refactoring is an important part of any coder’s process, not just advanced developers. For the less experienced audience, refactoring code is an excellent opportunity to learn and practice new techniques. Level up from get it done to get it done correctly!
We’ll go over five easy ways to refactor your beginner Python code, explaining the benefits of each and showing before and after code.
The first and probably most important refactoring we can do is defining functions for repetitive tasks. A function is a defined set of statements that can be executed by using the function’s name — known as a function call. …