Save
programming principles
module 2
Save
Share
Learn
Content
Leaderboard
Learn
Created by
cabbage
Visit profile
Cards (52)
Common data types
integer
float
string
boolean
Weak/Strong typing
Weak typing focuses on convenience, allowing
automatic
conversion between types. Strong typing focuses on
safety
, requiring explicit conversion.
Implicit and explicit conversion
Implicit conversion is
automatic
, while explicit conversion is done
manually
by the programmer.
Static and dynamic typing
Static typing requires declaring variable types, dynamic typing determines types based on
assigned values.
Numeric, string and boolean conversions
int
float
str
bool
Selection statements
If-then
If-then-else
Else-if
Boolean expressions
Expressions that evaluate to
True
or
False
Comparison operators
<
<=
>
>=
==
!
=
Variables allow assigning a
name
to data stored in
memory
for later use
Data types
are the "categories" of data, determining how the computer
interprets
the values
Most common data types
integer
float
string
boolean
Some languages have additional numeric data types for very
large numbers
or
large fractional parts
Some languages, like C, do not have a
string data type
, only a "
character
" type
Weak typing
Languages that focus on
convenience
by making it easier to mix and
automatically
convert data types
Strong typing
Languages that focus on
safety
by limiting the ability to mix data types, requiring
explicit
conversion
Conversion between data types can
fail
or result in data
loss
if it doesn't make sense
Many languages do implicit (
automatic
) conversion between compatible data types as needed, known as
coercion
Static typing
Requires declaring
variable
types, which must be
adhered
to
Dynamic typing
Determines
variable
types based on assigned values, no
declaration
required
In
statically typed
languages, trying to assign a value of a different type results in an
error
or coercion
In dynamically typed languages, variables can hold values of different
types
over time
Input() always returns user input as a
string
, requiring conversion for
arithmetic
Selection statements
allow choosing which code to run based on a
condition
The most common selection statement is
if-then
, which runs code if a
boolean
expression is true
If-then statements can be
extended
with else and
else-if
Boolean expressions evaluate to true or false, often using
comparison operators
Non-boolean values can be
coerced
to true or false
Selection statements
Choose which
code
to run based upon the result of a boolean expression - i.e. An expression that results in either True or
False
Comparison operator
Used to compare values and receive a
True
or
False
result
Function
Will return
(result in) either True or
False
Boolean
value
A non-boolean value can be
coerced
to either True or
False
Comparison Operators
Less
than
Less
than or
equal
to
Greater
than
Greater
than or equal to
Equal
to
Not
equal to
If-Then / Boolean Expression Examples
Comparing a numeric variable to a number
Using a
function
in a
comparison
Using a boolean
value
returned from a function
Using a
coerced boolean
value
Logical operators
Used to make multiple comparisons in a boolean expression
Logical
Operators
and
or
not
Python uses "
and
", "or" and "
not
" for logical operators
and
True if both comparisons are true, otherwise false
or
True if either (or both) comparison is true, false if they are both false
not
Reverse
/
Flip
true and false
Logical operators
are evaluated after evaluating the expressions on either side of them to True/False
See all 52 cards