MTEC1003 — Media Computation Skills Lab
Values
Types
Operations
Variables
Functions
and Input/Output
…but in Python, NOT JavaScript!
Python, like JavaScript, relies on simple functions and variables without engaging in class definitions.
but in MTEC1003, we’ll focus on the
fundamental similarities
between these two languages.
+
-
x
÷
%
(Parens)
Exponents (powers, roots)
Multiply
Divide
Add
Subtract
more on PEMDAS
<
<=
>
>=
==
!=
is
is not
more on Python operators
"Hi, I'm a string."
'also a string'
"string containing numbers: 4, 5.7"
"string ending with a new line\n"
"" # <= empty string
'' # <= empty string w/single quotes
"hello" + "there"
'you have ' + str(450000) + ' unread emails!!'
Wait, what’s going on in that last line?
We used str() to turn 450000 into a string.
Then we concatenated it into a larger string:
‘you have 450000 unread emails!!’
I mean, WOW.
1 + 3
4 x 5
Notice there is no semicolon at the end of a line in Python! And how do we do Statements in JS?…
1 + 3;
4 x 5;
Notice anything different?
Friendly reminder:
Remember in Javascript how we declare variables?
var x = "someValue";
Well, it turns out variables,
in all languages,
must be declared in some way…
This couldn’t be easier…
x = 'someValue'
So, what’s different?
We don’t need to type var to declare a variable.
In Python, a variable is declared
as soon as it’s assigned a value!
To execute (i.e. to “call”) a function,
type its name followed by parens…
print("you have 450000 unread emails!!")
print() is the funcion call.
Input to the function goes inside the parens.
So, the string is its input.
c.f. Functions in JS
answer = input("Say something! ")
print(answer)
1. Declare variable: answer
2. Prompt user with input()
3. Echo it with print()
c.f. same thing in JS
Now, time to do the labs…