1/82
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
var1, var2, var3 = 1, 2, 3
multiple variable assignment
12
integer
1.2
float
'twelve'
string
"twelve"
string
True or False
Boolean value
type()
determines type of an object (integer, boolean, etc)
int()
converts to integer object
float()
converts to float object
str()
converts to string object
print()
displays a message
+
addition (integer) or concatenation (string)
-
subtraction
**
power of
%
modulus, remainder
/
division, always results in float
//
division, always results in integer
=
assignment operator
+=
reassignment operator, adds
-=
reassignment operator, subtracts
*=
reassignment operator, multiples
/=
reassignment operator, divides
<
less than
>
greater than
<=
less than or equal to
>=
greater than or equal to
==
equal to
!=
not equal to
len()
returns length
title()
capitalizes first letter of each word
islower()
determines if the string consists of lowercase characters
count()
totals number of times an argument is found within a predefined value
format()
inserts variable data in a string
def
keyword used to create functions
def myfunction():
syntax for function declaration
return
defines output of a function
if age < 16:
creates an if statement
else:
else statement, used in conjunction with if statement or if/elif statement
elif age >= 16 and age <= 18:
elif statement, used in conjunction with if statement
True and False
False: and operation will always be false unless both sides are true
True or False
True: or operation will always be true unless both sides are false
not(True and False)
True: Boolean not operation will produce the inverse value.
myNumbers = [1, 4.8, 7, 9.2, 3, 0]
creates a list
mylist[0]
accesses first element from a list
mylist[-1]
accesses last element from a list
mylist[1:3]
slices list including second and third element
mylist[:3]
slices list beginning with first element and including through the third element. Index position 3 is not included in selection.
mylist[3:]
slices list beginning with fourth element and include remainder of the list
9.2 in myNumbers
looks for a match and returns Boolean value
9.2 not in myNumbers
ensures a match does not exist in list
len()
counts items in list
max()
returns greatest element of list
min()
returns smallest element of list
sorted()
returns copy of list ordered smallest to largest
sorted(listname, reverse=True)
returns copy of list ordered largest to smallest
sum()
returns total sum of list values
append()
adds new value to end of list
pop()
removes last item from a list
pop(1)
removes second item from a list
join()
joins values from a list using a defined separator
set()
creates a set, or a list that contains unique items
add()
adds value to set
discard()
removes value from set, if found
for city in cities:
iterates over items within a list
range()
defines a range of numbers
while temp >= 32:
iterates a set of commands as long as the condition remains true, stopping when the condition becomes false
break
loop command that stops iteration prematurely
studentGrades = { 'Orfu': 83, 'Bismark': 98, 'Igor': 72}
entries are added in key/value pairs
if 'key' in dictionary:
verifies if key exists in dictionary
get()
looks up value by key
myPhone = (877, 435, 7948)
creates a tuple
open('/my_path/my_file.txt','r')
opens a file object for reading
open('/my_path/my_file.txt','w')
opens a file object for writing
read()
reads data from open file
close()
closes open file
write()
writes to open file
with open('/my_path/my_file.txt','r') as f:
opens a file, performs operations and automatically closes file
import math
imports math module
from collections import defaultdict
imports individual function from a module
from csv import reader as scvreader
mports individual function from a module and assigns it a new name
$ pip3 install pytz
install package through the command line
import pytz
imports a package
split()
string method used to break apart a string and return a list