Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 6

SYMBOL SHEET

*** = doubt or not very clear

Keywords

KEYWORD DESCRIPTION
COMMAND
"and" logical and: True
and False == False
"as" part of the with as statement: with
X as Y: pass
*** "assert" ensure that something is true:
assert False, "Error"
*** "break" stop this loop right now or stop a
while True: break
loop:
*** "class" define a class:
class Person(object):
*** "continue" a command for a loop which shows
"don't process more of the loop,
while True: continue
do it again":

"def" define a function: def


area_one(argument): pass
*** "del" delete from directory works over a del
X[Y] where "X" is the name of dictionary and "Y" is key
variable: use in dictionary
"elif" abbreviation of else if statement elif
x == y: pass
used in to add more if conditions:
"else" else conditon it does not take any
else: pass
conditon true for all else condition:
*** "except" if an exception happens do this use this to
except ValueError, e: print(e)
pass an error:
*** "exec" run a string as python if you have a string
which contains a python code then it exec
"print("Hello World")"
will run it:
*** "finally" exception or not finally do this no matter
finally: pass
what:
"for" for loop which takes a list or tuple and for
X in Y: pass
execute nested code in a loop:

*** "from" imports specific part of a module into your from


X import Y eg from sys import argv
script:
*** "global" declare that you want a global variable holds
global X
for the entire code block:
"if" if statements takes a conditions and if that
condition is true it will execute its if X
== Y: pass here "==" is an operator
block of code:
*** "import" import a module into this one using this
command we can import a "module or feature"
import os
into our script:
*** "in" part of a for loop or can be str inside a for
X in Y: pass, or if X in Y: pass
variable for checking if statement:

*** "is" like equality test for equality "==": if 1


is 1: pass
*** "lambda" it creates a short anonymous function: lambda def
<lambda>(parameters):
parameters: expression works like
return expression

"not" logical not:


not(True and True): False
"or" logical or: True
or False: False
*** "pass" this block is empty: def
empty(): pass
"print" print the string:
print("Hello World!")
*** "raise" raise an exception when things go wrong:
raise ValueError("No")
"return" exit the function with a return value this
can be used as variable which is the result
return <function_name>(arg)
of a function: def <function_name>(arg):
*** "try" try this block, and if exception, go try:
pass
to except:
"while" while loop: an infinte loop which works the
while X == Y: pass
condition is not true:
*** "with" with an expression as a variable do:
with X as Y: pass
*** "yield" pause here and return to caller: def
X(): yield Y; X().next()

DATA TYPES

Type Description
Example
True Boolean True value True or
False == True
False Boolean True value True and
False == False
None represents "nothing" or "no value" x = None
bytes stores bytes maybe of txt or png or file etc. x =
b"hello"
strings stores textual information x =
"hello"
numbers/int stores integer value x = 123
floats stores decimals x = 12.45
lists stores data in lists j = [12,
"hello", 343, "I HATE IT!"]
dict stores key = value mapping things e = {"x":
1, "t": 4, 45: "hello"}

STRING ESCPAE SEQUENCES


Escape Description
\\ backslash
\n new line
\t tab a line
\b backspace
\v vertical tab
\' single quote
\" double quote
*** \a bell
*** \f formfeed: character that tells the terminal to
do whatever it thinks “form feed” should mean.
*** \r carriage: escape character and create a new
line

OLD STYLE STRING FORMATS


ESCAPE DESCRIPTION EXAMPLE
%d decimal integers(not floating points) "%d" % 45
== '45'
%i same as %d "%i" % 45
== '45'
%o octal number "%o" %
1000 == '1750'
%u unsigned decimal "%u" % -
100 == '-100'
%x hexadecimal lowercase "%x" %
1000 == '3e8'
%X hexadecimal uppercase "%X" %
1000 == '3E8'
%e exponential notation, lowercase "e" "%e" %
1000 == '1.oooe+03'
%E exponential notation, uppercase "E" "%E" %
1000 == '1.oooE+03'
%f floating point real number "%f" %
10.34 == '10.34000'
%F same as "%f" "%F" %
10.34 == '10.34000'
%g either %f or %e whichever is shorter "%g" %
10.34 == '10.34'
%G same as %g but uppercase "%G" %
10.34 == '10.34'
%c character fromat "%c" % 34
== '"'
%r repr format (debugging format) "%r" %
int == "<type 'int'>"
%s string format attaches a string "%s
there" % 'hi' == 'hi there'
%% a percent sign "%g%%" %
10.34 == '10.34%'

OPERATORS
OPERATOR DESCRIPTION EXAMPLE
+ addition 2 + 4 = 6
- substraction 4 - 2 = 2
* multiplication 4 * 2 = 8
/ division 4 / 2 = 2
% modulus gives remainder 2 % 4 = 2 or 4
% 2 = 0
** power of or exponents 2 ** 4 == 2 *
2 * 2 * 2 = 16
// floor division 2 // 4 = 0
when 2 / 4 = 0.500 so the floor division value here is first of quotient
< less than 4 < 4 == False
> greater than 4 > 2 == True
<= less than equal 4 <= 4 == True
>= greater than equal 4 >= 3 == True
== is equal to 3 == 3 == True
!= not equal to 3 != 4 == True
( ) paranthesis len('hi')
[ ] list brackets [1, 2, 3]
{ } dict curly braces {'x': 1, 'y':
3}
*** @ at(decorators) @classmethod
, comma to add more range(0, 10)
: colon in function it signifies def X():
starting of a block of code
. dot used for more attributes over self.x = 10
variable
= assign equal to x = 10
*** ; semi colon print("hi");
print("there")
+= add and assign x += 1
-= substract and assign y -= 2
*= multiply and assign x *= 3
/= divide and assign y /= 2
*** //= floor divide and assign x //= 4 here 4
is divisor x/4 will give an 'n' floor value
first divide and find floor value
*** %= modulus and assign x %= 2 here 2
is divisor and x/2 will give a remainder which will be assign
**= power assign x **=2 this
will assign x^2 = x

BITWISE OPERATOR DESCRIPTION EXAMPLE


~ "tilde" compliment of a bit a = 12, ~a = -
13 (12 binary format: 0000 1100)

compliment numb 1111 0011


we can't store
-ve so use like (~2 has ~1 +1)
& AND bitwise operator
| OR bitwise operator
^ XOR bitwise operator exclusive or
>> right shift in reality num is 45.00 12 >> 2 shifts
2 of last to decimal side [1100].[0000] -> [11].[000000]
so this will
be 0011 which 3
<< left shift just like >> but on left 12 << 2 shifts
[0011].[0000] -> [001100].[00]
side of the num
COMMANDS ON LISTS for () type here self = list_name: the definition of list can be
any sequence like 253532 or a name including spaces
COMMMAND DESCRIPTION
EXAMPLE
.append(value) add a value to list in the last
self.append(value)
'value'.join(list[from:to]) adds a value after every item in a
'#'.join(self(2:5)): 12#3#4#5678
lists starts from a item "from" to
item "to"
.pop() selects the last item in the lists
self.pop()
to for funtion
.index(cardinal no.) or selects a specific item inside a
self[1] 0 = starts -1 = last item
self[item no.] lists and shows it
.clear() removes everything inside a lists
self.clear()
.copy() return a shallow copy of lists
self.copy()
.count(value) counts the occurence of a specific
self.count(value)
value
.extend(iterable) extend a list by appending elements
self.extend
from a iterable
things[item no.] = new value this will repalce old value of the
value
list[from:to] takes values "from item no." to
list = [1, 2, 3, 4, 5, 6]
"to item no. - 1"(here it won't
list[2:4] = 3 4
include "to" item)
.sort() sort the list in asc-descending
.reverse() modifies a list to be in reverse
order
.remove(value) remove a specific value from list

COMMANDS FOR DICTIONARY


COMMAND DESCRIPTION
EXAMPLE
dict_name[key] this will give us the value designated
dict_name[key] = value
to the given "key"
*** list(dict_name.items()) this is used for loops inside it to
get for key, value in list(dict_name.items())
"key" and "value"
.clear() clears the whole dict_name
.keys() to view all keys of a dictionary
dict_name.keys()
len(dict.values()) == this functions checks if we have any
len(set(dict.values())) duplicates inside our dict(here"freq")

CLASS COMMANDS (X,M,J,K,Q and foo are like blank spots where we can designate them)

COMMAND DESCRIPTION
EXAMPLE
class X(Y) Makes a class named X that is-a Y
"is-a" a phrase to say that something is
salmon is-a fish
inherited from another.
"has-a" a phrase to say that something is
salmon has-a mouth
composed of a trait
class X(object): class X has-a __init__ that takes
these can also be called as attributes
def __init__(self, J): self and J as a parameters

class X(object): class X has-a M function that takes


def M(self, J): self and J as a parameters
foo = X() set "foo" to instance of class X
foo.M(J) from foo get the M and call it with
parameters
foo.K = Q from foo, get the K attribute and call
it Q
Iteration over input(int or string) = s(designated to a variable)
COMMAND DESCRIPTION
EXAMPLE
s[1:3] the input will be from indices
s = input(3432)
1 to 2 part is selected and will not
s[1:3] this will select 43
select indices 3
imp* we can't edit string but we can call specific value

METHODS PROVIDED BY STRING ON PYTHON


COMMAND DESCRIPTION
EXAMPLE
center return the string on a field of size w
string.center(200) field size = 200
count same as list
ljust returns a string on a field of
left-justified field size w
map(function, iterable)
(f"{variable:,}") add "," inside your string evenly
1,000,000,000

libraries to be learn
1. pandas***
2. python-dateutil
3. pendulum
4. NumPy***
5. Pywin32
6. Pytest
7. Seaborn
8. MoviePy
9. pip
10. Matplotlib***
11. PyKeyboard##
12. pyautogui##

You might also like