This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#format method merge si cu variabile | |
print('prices: ({x},{y},{z})'.format(x=20, y = 1.5, z = 5)) | |
print("The {vehicle} had {0} crashes in {1} months".format(2, 5, vehicle = 'dacia')) | |
#pentru a alinia la dreapta cu format: | |
#tre sa specificam caracterul care va inlocui spatiul gol si numarul de 'places' that the string will ocupy. | |
print('{:<20}'.format("text")) #aliniaza la stanga, gen in dreapta lui are 20 de spatii | |
print('{:>20}'.format("text")) #alin la dreapta, gen are 20 spatii in stanga lui 'text' | |
print('{:X>20}'.format("text")) #pune X-si | |
#aka prints XXXXXXXXXXXXXXXXtext | |
#pt a transforma 8 in binar cu format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//are doar o conditie care e evaluata, nu si pana cand.... | |
//daca vrei counter il pui inaintea loop: | |
var names= ['salam', 'parizer', 'ficat', 'maioneza', 'mici']; | |
var i = 0; | |
while (i < names.length) { | |
console.log(names[i]); | |
i++; | |
} | |
//break iese din loop | |
//continue quits the current iteration of the loop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var john = { | |
name: 'John', | |
lastName: "Smith", | |
yearOfB: 1999, | |
job: 'teacher', | |
isMarried: false | |
}; //obiectul john | |
console.log(john.lastName); | |
//asa vezi chestii in obiect .ceva | |
console.log(john['lastName']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shelve | |
#daca numele fisierului tau ar fi fost shelve | |
#ar fi dat eroare daca incercai sa import shelve ca mai sus | |
with shelve.open('ShelfTest') as fruit: | |
#they are read/write by nature | |
#so no need to specify the mode | |
fruit['orange'] = "a sweet, orange, citrus fruit" | |
fruit['apple'] = "good for making cider" | |
fruit['lemon'] = "a sour yellow citrus fruit" | |
fruit['grape'] = "a small, sweet fruit in bunches" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pickle #importi libraria pickle | |
#imelda is a touple | |
imelda = ("More mayhem", | |
"Imelda May", | |
"2011", | |
((1, "Pulling the Rug"), | |
(2, "Psycho"), | |
(3, "Mayhem"), | |
(4, "Kentish Town Waltz"))) | |
with open("imelda.pickle", "wb") as oriceNume: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for line in variabila: | |
print(line) | |
variabila.close() #inchide fisierul | |
#trebuie sa pui cate 2\\ ca sa nu fie interpretat aiurea de Python. | |
variabila = open("C:\\Users\\alexa\\Downloads\\sample.txt", ‘r’) | |
#printeaza doar liniile in care apare "jabberwock" | |
for ceva in variabila: | |
if "jabberwock" in ceva.lower(): | |
#convertim lowercase pt a cauta ceva |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tupla1 = ("cisco", "2750", "15.0") | |
vendor, model, Ios_version = tupla1 | |
#astea de sus NU TREBUIE PUSE INTRE GHILIMELE | |
#altfel va da eroare | |
print(vendor) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list4=[1,2,3,4,5,2,3] | |
print(set(list4)) #aplicam functia set pe lista | |
#printeaza {1 2 3 4 5} | |
set2=set([11,12,13,14,14,11]) | |
print(set2) #prints doar elem unice | |
set5= { 1,2,2,3,3,4} | |
print(set5) | |
set5.add(16) #adauga elementul 16 in setul respectiv | |
set5.remove(16) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#unpacking tuples from a list of tuples | |
#cand ai doua valori inainte de in (ex: a si b) | |
#a ia prima valoare, b urmatoarea, apoi a ia a treia valoare, b a 4a etc | |
list_of_tuples= [(1,2),(3,4)] | |
print(list_of_tuples) | |
for a,b in list_of_tuples: | |
print("a:", a,"b:",b) | |
#prints a:1 b:2 a:3 b:4 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#========EX5========== | |
#NOW WE WANT PLAYERS TO ENTER THE NAME OF THE LOCATIOn, not a direction | |
#so you can just type 'valley' and go there | |
#so we add road, hill etc to the vocabulary | |
"""So we can't store the directions in Vocabulary. Instead, we store the location numbers, then map them | |
to the appropriate location. | |
From the Valley, typing Road should go north, so the vocabulary maps "ROAD" to "1" | |
and in the exits entry for Valley we map "1" to location 1. | |
Typing Hill from the Valley needs to take you West, so we map "HILL" to "2", then in the Valley's exits entry | |
we map "2" to location 2 (which is the hill).""" |