In [10]:
a=45
print(a)
In [11]:
b=25
print(b)
Okay, neat. Can I only make variables that hold numbers?
In [12]:
x="Hello Everybody!"
print(x)
In [13]:
Amiright=True
print(Amiright)
Wait a minute, the numerical variables above are only integers...can we use decimal points?
In [14]:
fl = 0.54
print(fl)
Wow look at all those variables! What do I call them all?
Terminology
Integer:Any whole number:42,2635
Float:Any number at all
String:Anything with letters in it
Boolean:Any True or False statement
These will become useful when you get an error and you are wondering what it means.
In [15]:
print(a)
print(b)
c=a+b
print(c)
Note that our a and b didn't go away. Variables will stick around until you change them.
In [16]:
c=a/b
print(c)
c=c+a
print(c)
We have the usual arithmetic operators, $+, -, /, *$. On top of that we also have the power operator, $**$, the modulo operator $\%$ which returns the remainder from a quotient, the additive equality operator $+=$, and the equality operator, $=$. We also have the comparison operators; $>,<,==, !=, and, or$. Which mean, greater than, less than, is equal to, is not equal to, and, or.
In [28]:
#addition
print(2+2)
#division or quotient
print(42/42)
#multiplication
print(2*3)
#subtraction
print(2-8)
#exponent or power
print(2**3)
#modulo or remainder
print(10%7)
#additive equality
a=56
a+=10
print(a)
#greater than
print(10>5)
#less than
print(10<5)
#is equal to
print(11==10)
#is not equal to
print(10!=10)
#and
print(11==11 and 12>10)
#or
print(10==11 or 5<7)
Let's explore how a computer thinks about strings. Beginning with some natural ideas.
In [20]:
string="hiya"
print(len(string))
In [21]:
print(string[0])
In [25]:
string1=" there!"
print(string+string1)
In [26]:
print(string-string1)
The computer sees the string as a list of individual letters. In the next section, we will discuss lists in a more general sense. In the previous example, we had two strings, "heya", and " there!". The computer sees "heya" as
$$\left["h", "e", "y", "a"\right]$$
In [ ]: