Variables, Types, and print
Store a placeholder host label, a check count, and a True/False flag, then print them and their types.
Based on the official Python documentation. Date checked: November 27, 2026. Script tested on Python 3.13.5.
Series: Python for small scripts, Part 2 of 10. Previous: Part 1: Install Python 3 and Run Your First Script. Next: Part 3: Decisions with if, elif, and else.
TL;DR
- A variable is a name that holds a value.
- This script stores a placeholder host name, a count, and a True/False flag, then prints them.
- An f-string lets you put a value inside a line of text.
- Tested on Python 3.13.5. This is Part 2 of 10.
Before you start
- Python 3.11 or newer. This script was tested on Python 3.13.5. Check with
python3 --versionorpython --version. - Work in the
python-scriptsfolder from Part 1. - Run with
python3 values.py. On Windows,python values.pyis the usual form.
The finished script
Save this as values.py in that folder:
host = "<host>"
check_count = 3
ok = True
print("Host:", host)
print("Checks:", check_count)
print(f"Status: {check_count} checks, ok={ok}")
print(type(host))
print(type(check_count))
print(type(ok))
When you run it, you should see:
Host: <host>
Checks: 3
Status: 3 checks, ok=True
<class 'str'>
<class 'int'>
<class 'bool'>
Steps
- Save and run the script. In the terminal, change into
python-scriptsand runpython3 values.py. Why: you can see the stored values and their types before you change anything. You should see: the seven lines above. - Read the three assignments.
hostholds text, which Python calls astr.check_countholds a whole number, anint.okholdsTrueorFalse, abool. The angle brackets in"<host>"are ordinary characters; they mark a placeholder, not a real machine name. Why: later steps will combine these values, and each type has different rules. - Look at the f-string. The
fbefore the quotes marks a formatted string literal.{check_count}and{ok}are replaced with the current values. Why: this is the usual way to build one message from several values. You should see:Status: 3 checks, ok=True. - Change a value and run it again. Set
check_countto5and save the file, then run the script again. Why: a variable keeps the last value you assigned. You should see:Checks: 5andStatus: 5 checks, ok=True.
If it fails
NameError: name 'host' is not defined. You used a name that has not been assigned, or the spelling differs. Check the left side of each=line, then run the script again. A short file that only containsprint(host)produces this traceback:
Traceback (most recent call last):
File "nameerror.py", line 1, in <module>
print(host)
^^^^
NameError: name 'host' is not defined
The File path will show the folder where you saved the file.
TypeError: can only concatenate str (not "int") to str. A line such asprint("checks: " + 3)tries to join text and a number with+. Use an f-string, or convert the number withstr(3).- A string looks unfinished, or Python reports a
SyntaxErroron the quotes. Every opening quote needs a matching closing quote on the same string.
Stay safe
- Use placeholders such as
<host>. Do not put a real hostname, username, or address in the script. - Do not paste passwords, tokens, or keys into a variable in a file you might share.
- This script only prints values. It does not connect to a network or change files.
Next
Part 3: Decisions with if, elif, and else
Sources
- Python docs, “An Informal Introduction to Python” (docs.python.org/3/tutorial/introduction.html), Python 3.15.2 documentation, checked November 27, 2026.
- Python docs, “Built-in Types” (docs.python.org/3/library/stdtypes.html), checked November 27, 2026.
- Python docs, “Formatted string literals” (docs.python.org/3/tutorial/inputoutput.html#formatted-string-literals), checked November 27, 2026.
Spot something wrong or outdated? Leave a comment below. Every comment is reviewed to keep these posts accurate.
By commenting, you agree to our Terms of use and confirm this is your own work. Short quotes are fine with a credit and link. Copied, unsafe, or abusive comments are removed. See something copied? Say so here.