Beginning Python: Setting up Python & Variables
2025-09-29
grep and regexwc file.txt → identify number of lines, words, and characters in file.txt
-l, -w, -cgrep "word" file.txt → search for a string in a filegrep "word" file.txt | wc -lregex:
., [...], [^...], [a-z], etc.We defined what kind of document we were writing with documentclass{}
We imported additional code, with \usepackage{}
We wrote out instructions for how the document was supposed to look with commands like
Then, we used a LaTeX engine (using Overleaf) to interpret the LaTeX code, which returned a result in the form of a typeset pdf.
<!DOCSTRING html>CSS, into the HTML document.<strong></strong>HTML document, and the browser returned a result in the form of a website.RegEx!HTML or LaTeXWhen we write a Python program, we will:
#! /usr/bin/python3LIN_301 directorypy.
Visit: https://www.python.org/downloads/
Download the latest version for your OS
Once it’s installed, verify that it works in your RStudio Terminal:
print:" within the print function
' instead!print(Hello world!). What happens?.py file, called first_script.pyRun in the document to run the code..qmd) is a plain text file that mixes:
Quarto Document, called first_doc.qmdhtml file.qmd file, and try this instead:print(hello_world) work, but print(Hello world!) didn’t?hello_world is a variable that we defined as having the value "Hello world!"hello_world ≠ Hello_world)_
&, *, ., ?my_age using =:year_of_birth still has the old value.Let’s extend what we’ve learned with variables:
30.Python code block.child_18_year, which is the year your child turns 18.+ and -current_year = 2025
my_age = 20
# How many years until you turn 30?
years_til_kid = 30 - my_age
# What year is the child born?
child_birth_year = current_year + years_til_kid
# What year does the child turn 18?
child_18_year = child_birth_year + 18
print(child_18_year)