print
is the equivalent of console.log
.
‘print() == console.log()’
#
is used to make comments in your
code.
Python has a built in help function that let’s you see a description of the source code without having to navigate to it… “-SickNasty … Autor Unknown”
Created by a literal non-decimal point number … or … with theint()
constructor.
Consist of a real part and imaginary part.
If you came from a background in JavaScript and learned to accept the premise(s) of the following meme…
Than I am sure you will find the means to suspend your disbelief.
Thei
is switched to aj
in programming.
Math.floor()
in JS.
++
and --
in Python, the only shorthand
operators are:
'Jodi asked,
"What\'s up,
Sam?"'
len()
function to get the length of a
string.
zero-based indexing
slice
in JS.
index
string function is the equiv. of indexOf()
in JS
count
function finds out how many
times a substring appears in a
string… pretty nifty for a hard
coded feature of the
language.
+
to concatenate strings, just
like in JS.
format()
function to use placeholders in
a string to input values later
on.
print(f'Your name is
{first_name}
{last_name}')
join
is used on an Array, in Python
it is used on String.
NaN
does not exist in Python, but
you can 'create' it
like so:
print(float("nan"))
null
with none
.
none
is an object
and can be directly assigned to
a variable.
Using none is a convenient way to check to see why an action may not be operating correctly in your program.
None
or False
True
and False
must be capitalized
Just like in JS, you can useparentheses
to change the inherent order of operations.
Short Circuit : Stopping a program when atrue
orfalse
has been reached.
is
and is not
over ==
or !=
Remember the order ofelif
statements matter.
Break
statement also exists in
Python.
continue
statements
try/catch
pass
commmand to by pass a certain
error.
pass
method won't allow you to
bypass every single error so you
can chain an exception series
like so:
else
statement to end a chain of except
statements.
finally
is used at the end to clean up
all actions under any
circumstance.
def
keyword
lambda
keyword is used to create
anonymous functions and are
supposed to be one-liners
.
toUpper = lambda s: s.upper()
Remember that in Python join() is called on a string with an array/list passed in as the argument. Python has a very powerful formatting engine. format() is also applied directly to strings.
List Tuple Range Collections : Unordered data structures, hashable values.
Start : opt. default 0, first # in sequence. Stop : required next number past the last number in the sequence. Step : opt. default 1, difference between each number in the sequence.
Benefit of dictionaries in Python is that it doesn’t matter how it is defined, if the keys and values are the same the dictionaries are considered equal.
Always be unique, duplicate items are auto dropped from the set.
Removing Duplicates Membership Testing Mathematical Operators: Intersection, Union, Difference, Symmetric Difference.
zip(*iterables) : creates a zip object filled with tuples that combine 1 to 1 the items in each provided iterable. Functions that analyze iterable
1. The for keyword 2. A variable name 3. The ‘in’ keyword 4. An iterable of some kid 5. A colon 6. On the next line, an indented block of code called the for clause.
Prints 1, 2
Prints 3, 4
Prints 5, 6
module : Python code in a separate file. package : Path to a directory that contains modules. init.py : Default file for a package. submodule : Another file in a module’s folder. function : Function in a module.