







Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Prepara i tuoi esami
Studia grazie alle numerose risorse presenti su Docsity
Prepara i tuoi esami con i documenti condivisi da studenti come te su Docsity
Trova i documenti specifici per gli esami della tua università
Preparati con lezioni e prove svolte basate sui programmi universitari!
Rispondi a reali domande d’esame e scopri la tua preparazione
Riassumi i tuoi documenti, fagli domande, convertili in quiz e mappe concettuali
Studia con prove svolte, tesine e consigli utili
Togliti ogni dubbio leggendo le risposte alle domande fatte da altri studenti come te
Esplora i documenti più scaricati per gli argomenti di studio più popolari
Ottieni i punti per scaricare
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Il documento contiene gli appunti per imparare a muovere i primi passi con PHYTON. Tali appunti sono stati estrapolati dai documenti e dalle lezioni tenute dalla professoressa GAIA RUBERA, nel corso di SOCIAL MEDIA MARKETING presso l'università BOCCONI.
Tipologia: Appunti
1 / 13
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!








Numbers
Series of alphanumeric characters
Ordered collection of objects
Unordered collection of unique objects
Immutable list of objects
Associate unique keys to specific values
name_integer=value
CREATE integer "num" whose value is 3
num= print(num)
name_string=”value”
CREATE a string whose value is “cheese” and whose name is “food” food="cheese" print(food)
Print the sentences:
name="Ryan" age= print(name+" is "+str(age)+". He likes "+food) OR print(name,”is”,age,”. He likes”,food)
name_list= “a”,”b”,”c” made by strings name_list= 1,2,3 made by integers name_list= a,b,c made by variables
. CREATE a list of STRINGS called “greenday”, which contains the name of the members greenday= ”Billie”,”Tre Cool”,”Mike” print(greenday) . CREATE a list of INTEGERS primes= 1,3,5,7 print(primes) . CREATE a list of VARIABLES singer=”Billie” drummer=”Tre Cool” bass=”Mike” band= singer,drummer,bass print(band)
List1= 1,3,5,7 Select the:
CREATE a set from the list 1,2,3,3,4,4,5,5,6,7,8,9,0 set1=set( 1,2,3,3,4,4,5,5,6,7,8,9,0 ) print(set1) 0,1,2,3,5,6,7,8,9 -> length=
Convert STRING to a LIST: Name_list=name_string.split()
Convert a LIST of words into a STRING: Name_string=” “.join(name_list)
name_tuple=(“a”,“b”, …) made by strings name_tuple=(1,2, …) made by integers name_tuple=(“a”,1), (“b”,2) made by different types of objects (list of tuples)
. CREATE a tuple of STRINGS students=(“Kirs”,”Paul”,”Mark”) print(students) . CREATE a tuple of INTEGERS grades=(30,23,25)
print(grades)
. CREATE a tuple of DIFFERENT TYPES of objects student_grades=(“Kirs”,23), (“Paul”,30), (“Mark”,22)
RETRIVE the first element of the tuple “grades” print(grades 0 )
. CREATE a list from two tuple zip (students,grades) students2= list (zip(students,grades)) print(students2)
name_dictionary= key1:value1, key2:value2
Keys can be strings, integers or tuples but no lists
. CREATE from SCRATCH grades= “Kirs”:30, “Paul”:23, “Mark”:25 Print(grades) . CREATE from LIST names=(“Kirs”,”Paul”,”Mark”) grades=(30,23,25) grades2= dict (zip(names_key,grades_value))
If we try to retrive a key and it does not exist print(grades ”Abbie” ) KeyError: “Abbie”
CHANGE the value of a dictionary grades ”Mark” =
ADD a new item to a dictionary
Is a mechanism for which computer repeats the same block of codes multiple times
For
aaa= print(element1=aaa+1) 3
aaa= print(element1=aaa+1) 4
aaa= print(element1=aaa+1) 5
list1=2,3,4 For aaa in list1: per tutti i valori nella list1: element1=aaa+1 sommaci 1 print(element1) 3 4 5
2. range function for aaa in Range(0,3): per tutti i valori compresi tra 0 e 3: Print(aaa) mostrali 0 1 2 OR List1= 2,3,4 For aaa in range(len(list1)): this is the equivalent of range (0,3) -> for aaa in range(3) Print(aaa) 0 1 2 we obtain the indices of list1 (aaa=index of elements in list1)
For aaa in range(len(list1)): Element1=list1 aaa + 3 4 5
Two different ways to ITERATE over a LIST:
CHAMPIONS= ”Real”: 13,”Milan”:7,“Juve”:2
Students= ”Kris”: ”grade”: 30,”skill”: “math” , ”Paul”: ”grade”: 29,”skill”: “latin” , ”Mark”: ”grade”: 22,”skill”: “engineering”
Is a block of resuable code that you can use to perform specific action.
Def
We want to define and call a function that multiples two numbers and returns the outcome of this multiplication Def multiplication(a,b): mult=a*b return mult print(multiplication(3,5)) 15
print(input)
print(type(object))
name_object_WantToChange=new_value name_object “Changing_element_index” =new_value
name_object “New_element” =value
delList_name index
element1+element sum(list_name) OR sum(element1,element2)
LENGTH (number of elements) len(object)
BOOLEAN (check if 2 objects are the same) object1==object
RETRIEVE (select an element of a list) list_name index
SLICE (select few elements of a list) list_name index_first_INCLUDE:index_first_EXCLUDE
object.method()