VOOZH about

URL: https://thenewstack.io/more-python-for-non-programmers/

⇱ More Python for Non-Programmers - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2021-12-02 09:00:48
More Python for Non-Programmers
tutorial,
Python / Software Development

More Python for Non-Programmers

Wrote your first program in Python!
Dec 2nd, 2021 9:00am by Jack Wallen
👁 Featued image for: More Python for Non-Programmers

So you’ve taken your first steps with Python with the help of “An Introduction to Python for Non-Programmers.” You understand what Python is, why it’s a high-level, general-purpose language, and you’ve even written your first application with the language.

That’s exciting. But there’s so much more to learn. Fortunately, this language is really easy to get up to speed with (although it will take a while to really master). What I want to do this time around, is move you forward a bit with the language, all the while making sure you understand the concepts as a non-programmer.

It’s really easy to teach someone who firmly grasps the concepts of code. But when you’re absolutely new to the game, those concepts can fly right over your head.

Let’s make sure that doesn’t happen.

In the first piece, I explained what a function is and showed you how to use the print() function in a simply Hello, World! application. We’re going to build on that, but first I want to show you an easy way to test your function skills from the Python console.

What Is the Python Console?

Remember how you used the print() function within the Hello, World! app? For a refresher, the file used for that app is:

#Print out the text "Hello, New Stack!".
print('Hello, New Stack!')

The file consists of a comment (the first line) and the code that makes the app run. To run the app (named hello-newstack.py), the command would be:

python3 hello-newstack.py

You remember that, right? Okay, what if you wanted to first make sure you knew how to write that function properly, without adding it to the file? To do that, you could open the Python console, which is a quick and easy way to test and execute Python commands.

Say, for instance, you want to create a Python app, but before you add a new line of code to it, you want to make sure the code works. Let’s use our print() example.

To access the Python console, open a terminal window (on the machine that has Python installed) and issue the command:

python3

You should now find yourself in the Python console (Figure 1).

👁 Inside the Python console.

Figure 1: The Python console is ready to test and execute your commands.

Go back to the print() function by issuing the command:

print('Hello, New Stack!')

You should see Hello, New Stack! printed in the console.

To exit out of the console, you have to type another function, which is:

exit()

Hit Enter on your keyboard and you’ll be back at your computer’s terminal window.

How to Use Variables with Python

Now that you know how to create a very basic Python application and different ways to execute Python commands, let’s create a new application, one that contains a variable. What is a variable? In terms of programming, a variable is used to store specific information that will be referenced within the code.

Here’s a very simple example. Let’s say you need to use a date within your program. Instead of always having to type out the necessary date, you could set it as a variable like so:

date = "Thursday November 18, 2021"

We’ve now set our variable. Let’s use it in an application. Create a new file with the command:

nano date.py

In that file, we’ll set our variable by adding the line from above, so:

date = "Thursday November 18, 2021"

Our program won’t be much good with just the data variable set. Let’s make use of the variable by printing it out with the print() function like so:

print(date)

Our full application looks like this:

date = "Thursday November 18, 2021"
print(date)

Save and close the file. Execute the program with:

python3 date.py

You should see “Thursday November 18, 2021”, printed in the terminal window.

Let’s expand on that. As is, our application isn’t any good if we run it on, say, Friday 19, 2021, because it’ll print out yesterday’s date. Instead of explicitly setting the data variable we can use a function that stores today’s date as the date variable. That function is date.today(). Using that function, we set our variable with:

date = date.today()

The above line would use the date.today() function to set the date variable to whatever the date was when the application is run.

However, there’s already a problem. The date.today() function isn’t available to use without first loading it. How do we do that? Easy. What we do is import the date function from the DateTime module with the line:

from datetime import date

With that line at the top of our file, date will be available to any function that calls it. So now our new application looks like this so far:

from datetime import date

date = date.today()

Outstanding. Next, we’re going to add the line that actually prints out the information, which makes our little application useful. But instead of just printing out the results of the date variable, we’d add the text line “Today’s date is:” That print() line would look like:

print("Today's date is:", date)

Our entire application would look like this:

from datetime import date

date = date.today()
print("Today's date is:", date)

Let’s add comments, so we know what each section does:

#Import date function from datetime module.
from datetime import date

#Set date variable using date.today() function.
date = date.today()

#Print today's date.
print("Today's date is:", date)

Save and close the file. Run our new application with:

python3 date.py

The output should be:

Today's date is: 2021-11-18

Of course, the date in the output will change, depending on the date you run the application.

And there you go, you’ve taken your next step with the Python programming language. When next we visit this topic, we’ll create an application that accepts input from a user.

TRENDING STORIES
Jack Wallen is what happens when a Gen Xer mind-melds with present-day snark. Jack is a seeker of truth and a writer of words with a quantum mechanical pencil and a disjointed beat of sound and soul. Although he resides...
Read more from Jack Wallen
SHARE THIS STORY
TRENDING STORIES
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.