(base)at the beginning of the prompt
$, and other parts of the prompt (e.g. the path)
conda create -n cs110 matplotlib pyqt==5.15.7 pytest
This creates a python environment named cs110 that has the libraries
pytest included in it.
conda activate cs110
This activates the cs110 python environment we just created.
(base) has changed to
Python is a programming language.
Humans can describe the things they want the computer to do using a language and style that is comprehensible to humans.
Python the program converts python code into instructions the computer understands (1's and 0's).
There are two ways to run python:
Open your terminal and run:
This will start the python console.
You'll know python is running because the terminal prompt will start with
1 + 1
2 * 5
Among many other things, python can do math!
1 + 1
9 - 6
2 * 4
6 / 3
/ symbols are called operators.
Python has a few other mathematical operators you may be less familiar with (but can be quite handy in some programming scenarios). We'll learn more about them later.
Evaluate the following python expressions in your python console:
7 + 5
8 - 3
2 * 5
9 / 2
Python makes a distinction between integer numbers (
ints) and floating-point numbers (
int is a positive or negative whole number (including 0). e.g.
float is a real number with a decimal point.
The distinction and purpose of these two kinds of numbers will become clearer over time.
For now, just be aware that both ideas exist.
4 * 4
4 * 4.0
A character is a single letter or symbol. Like
(that's a space)
Strings are strings of characters.
Python uses double or single quotes (
') to indicate a string.
'My name is Dr. Bean'
'1 + 1'
Sometimes you want your program to display information.
You can use the
A function is a block of code that you can run more than once.
It's like a recipe. The recipe has a series of instructions to follow. You can make the same recipe as many times as you want.
print('Printing is boring...') print('I love printing stuff!') print('I can print all kinds of stuff.') print('This is fun!')
Because the computer cannot handle the least degree of ambiguity, every instruction we provide must be precise and exact.
The rules about how our instructions are composed are called syntax.
When you violate these rules, you get a syntax error.
"Hello, my name is Inigo
A quick brown fox"
print(1 + 7
7 /// 5
8 *** 3
print('They said to say something intelligent")
The python console is a REPL (read-eval-print-loop).
It reads one line of instruction, evaluates that instruction, prints the result of that instruction, and does it again!
In addition to the python console, I can also write a python script.
A python script is a file with the extension
.py that contains python statements.
I can then run a python script from my terminal.
For example, if I make a file named
hello.py with the contents
I can run or invoke the script from my terminal (assuming
hello.py is in my current directory):
This demonstrates one of the lab activities
cdto the directory containing the file.
The console echos the value of the last expression.
Scripts don't do this.
If you want a python to print something in a script, use