Section 1

Preview this deck

division

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (48)

Section 1

(48 cards)

division

Front

5/8 or 5//8 which gives you whole number only and 5%8 which gives remainder and (7./2 or 7/2. or 5%8) gives you a float = 3.7

Back

conditions and control flows

Front

if cars for conditions then runs code ex. if 8<9 print" eight is less than nine!" elif is like a continuation with new statement when if statement dont work ex. if 8>9 print "bah" elif 8 < 9 print "dibassy" else does not take condition or last resort it is the last resort ex.print keilly

Back

subtraction

Front

5-8

Back

update variable

Front

regular = points _ per _ total =5 and point _ total =500 updated variable is point _ total + point _total =

Back

change keys

Front

ex. menu ['spam'] = 2.50 dict_name [new key] = heaven can be deleted be del dict_name [key_name] or add new value dict_name [key] = new _value or remove things ex. Beatles = ("john", "paul", "george",) beattles.remove ( "paul") = john, george

Back

universal import

Front

this is when we want all the variables and functions but dont want to consistantly type math. universal import syntax is from module import in this case math dangerous because there are lots of functions with the same name

Back

example of for loop

Front

example. my_list in my-list = [1,9,3,8,5,7] for number In my_list: ^ we just made a new variable, anything after for becomes a new variable print 2*number = 2,18,16,10,14

Back

other stuff about keys

Front

sort keys--> inventory['pouch'].sort() ^ ^ name key delete --> inventory ['backpack'].remove ('dagger') ^ value add. inventory ['gold'] = inventory [gold] + 50 ^ added value

Back

parameters and arguments

Front

parameter is a variable that is an input to a function. so when the function is used we will be able to input any value. but the current value will be or whatever . a function can have any number of parameters an argument is the value of parameters passed into the function . are known as arguments ex. square(10)

Back

Front

Back

order of operations for booleans

Front

1st is NOT 2nd is AND 3rd is OR ex. True or not false and false = true

Back

function import

Front

we only need the sqrt function so it can be frustrating to have to keep doing math.sqrt() instead we can do from math import sqrt now we can just type sqrt to get square root instead of adding math.

Back

Front

Back

functions example

Front

def square(n) " return the square" square = n print "%d square is %d" %(n, squared) return squared square(10) ^ the square is called by outside user

Back

booleans

Front

or is either or checks if 1 is true ex. 1<2 or 2<3 is true and means that both have to be true ex. 1<2 and 2<3 is true not is the opposite of a statement so not true is false and not false is true ex. not 41 > 40 this will return flash

Back

for loop

Front

used for when you have a block of code you want to repeat ex. for variable name in list : or for i in range(5) print i --> = 1,2,3,4 (will not print 5) inorder to skip u do i==(num) ex. i == (3) --> 1,2,4

Back

type()

Front

this function gives us the type of data it receives ex. print (42) print (4.2) print("spam") =int =float =string

Back

Multuplication and exponents in python

Front

(5 x 8) and 5××8 which is (5^8)

Back

raw_input

Front

Raw input acceptes a string prints and the waits for the user to type something and return by pressing enter ex. name = raw_input ("what is your name?>>" python then ask us what is your name I type Mohammed so name = mohamad is saved for numbers use int(raw_input("how many apples")

Back

converting integers to strings

Front

we use str() EXAMPLE: "I am" + str(age) + "years old"

Back

example of calling function

Front

def fun_one(n) return n×5 or def_two (m) return fun_one(m) + 7

Back

list

Front

data type used to store different info under single variable ex. list _ name = [item 1, item 2] if you want to access index --> list_name [numb] replace list by zoo_animals[2] = 'heyena' you can also add to a list whenever you want ex. letters = (a,b,c,) letters.append ('d')= [a,b,c,d,]

Back

dot notation

Front

calls on functions from class that makes objects example say_name.mohamad

Back

String concentation

Front

the + operator adds strings together example : "life is" + "good" = life is good

Back

.isalpha

Front

used to make sure that a string does not contain any non letter characters ex. x = "j123" x.isalpha = false returns true if letters are alphabets

Back

Front

Back

maintaining order

Front

we can search for items in lost ex. animals = ["ant", "bat", "cat"] print animals.index ("bat") or insert ex. animals.insert (1 , "dog") we want to add dogs 1 index so it will now look like["ant", "dog" , "bat", "cat"]

Back

make a key

Front

ex. inventory = { key --> 'gold' : ['flint' , 'money', 'food' }

Back

string formatting with %

Front

another method to print a variable with a string name = 'mike' example : print "hello%s" % name is "hello mohamad" and in order to print variables with numbers do %d age = 5 example: "I'm %d years old" %age I'm 5 years old

Back

Front

Back

string methods

Front

cool things you do to strings lower method: turns strings into lower case example: name = 'John Doe' name.lower() = john doe upper method turn things to upper case example = john doe.upper = JOHN DOE len() counts how many letters there are example: bah = "mohamad" print len(bah)

Back

strings

Front

if u want your strings to span multiple lines we need to use 3 quotes EXAMPLE: """hello Bah""" we can make strong one comma 's' or two comma "s" another way to use strings is by backslapping for example ' I/M' looking for someone' -- this tells python to continue and disregard the second comma

Back

min()

Front

takes smaller number ex. min(123) = 1

Back

index

Front

in python each letter or character is assigned an index and it starts from 0 and goes up help us find objects position in list EXAMPLE: python 012345

Back

functions

Front

header of the function includes def keyword, name of function and parameters ex. def hello_ world() an option to explain what code does the body that describes the function and the call and response

Back

generic import

Front

if I print sqrt(25) I will get an error I have to bring up the math module where math related variables and functions are saved. then if i print sqrt(25) python will give me 5 modules are basically a file which can show classes,function and global variables. like diff chapters or position in ball...gives us functionality ex. if I wanted to make a web request I could import the module "ur lib" another example import math print math.sqrt(25) this tells python not to only import math but the square root function that's why we add math. whatever

Back

keys(also called dictionaries)

Front

can access stuff by looking up keys keys can be any string or number ex. residents = {'puffin' : 104, 'sloath' : 105, ' burmese python'} print residents [ 'Puffin'] print residents ['sloath'] print residents ['burmese python'] =104 =105 =106 keys are like using keys to get value ex. employees { 1 : " bah,2 : "papa"} employees [2] = papa

Back

date time library

Front

allows you to keep track of date and time example: now= datetime.now() if you want specific date and time print now.year = 2018 print now.month = 6 print now.day = 30 if we want the hot date format then we use example: print "%02d/%02d/%04d" % (now.month/ now.day/ now.year) is 06/30/2018. and the (pretty time ) is now = datetime.inow() print now.hour print now.minute print now.second print'% 02d:%02d:%02d' % (now.hour,now.minute,now.second) is 03:32:34

Back

list

Front

slicing is another way of getting values from list ex. prime >>[2,3,5,7,11,13,17,19] 0 1 2 3 4 5 6 7 8 primes[2:5] =[ 5,7 11] ^ ^ ^ name staring ending since index 2 is called we start from 2 and go up to index 5 which is 13 but we dont print index 5 the last number we stop at 4

Back

Front

Back

Front

Back

.sort()

Front

sort it into ABC order ex. animals = ["cat","ant","bar" animals.sort () for animal in animals : print animal ="ant" "bat" "cat" another example start_list =[ 5,3,1,2,4] square _list = [] for number in start_list: square _list.append(number, xx2) square_list.sort() print square_list = 1,4,9,16,25

Back

Boolen Operators

Front

anything imputed in the conusle that can be true or false == this compares != not equal

Back

max()

Front

takes the number of arguments and gives us the largest ex. max(1,2,3) will return 3

Back

slicing list and strings

Front

when you want to slice a string and want a specific part putting the index on second half of ration means everything b4 that index will slice. ex. animals = "cat, dog, frog" cat = animals [ :3] ^ means cut cat when the index is in front everything after it will be taken ex. animals = "cat,dog,frog" frog = animals [6 : ]

Back

string to a number

Front

we use int() EXAMPLE: int_addition = int (number 1)

Back

abs()

Front

gives absolute of number ex. return absolute value of a number abs(-3) = 3

Back

6 comparator

Front

equally to ( ==) not equally to (!=) less than (<) less than or equall to (<=) greater than (>) greater than or equall to (>=)

Back