-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvar.py
More file actions
34 lines (26 loc) · 774 Bytes
/
Copy pathvar.py
File metadata and controls
34 lines (26 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Sintassi più compatta per assegnare più valori a più variabili
from json import JSONEncoder
x, y, z = "Orange", "Banana", "Cherry"
print(x)
print(y)
print(z + '\n')
# Lo si può fare anche con un array come LValue
fruits = ["apple", "banana", "cherry"]
x, y, z = fruits
print(x)
print(y)
print(z + '\n')
# Il JSON è chiamato dizionario, ma le chiavi devono essere stringhe:
json = {
"nome": "Davide",
"cognome": "Scalisi"
}
print(json)
print("Nome: %s\n" % json.get("nome"))
# Per quanto riguarda lo scope, si può dichiarare anche una variabile globale
# dentro uno scope diverso da quello globale tramite la parola chiave global:
def myfunc():
global x #Variabile globale.
x = "fantastic"
myfunc() #Creo la variabile globale.
print("Python is " + x)