Escolar Documentos
Profissional Documentos
Cultura Documentos
#Assignmernt Operators
$ x = 10 # Attach value
$ x = x + 5 # Sum value
$ x += 5 # Sum value
$ x -= 5 # subtract value
$ x *= 5 # multiply value
$ x /= 5 # divide value
$ x %= 5 # Valide how to much number 5 have in x value and return the surplus
value
#Condition - If
$ if speed > 110:
$ print('The speed is high that allow')
$ elif speed < 60:
$ print('please drive high that 80kms/h')
$ else:
$ print('Ok Speed')
#Multiple Operators
$ value = 25
$
$ if 20 <= value < 40: # low or equal than 20 and low than 40
$ print('Product allow')
$
$ if value >= 20 and value < 40:
$ print('Product allow')
#while loop
$ value = 100
$ while value > 20:
$ print(f'Sale!! Value is R${value}')
$ value -= 10
#Ternary Operator
$ age = 12
$ result = 'Vote is allow' if age >= 18 else 'Vote Not allow'
$ print(result)
#Function + list
$ name = ["Ford", "Volvo", "BMW"]
$ quantite = ["10", "20", "30"]
$
$ def welcome(name, quantite): #default value
$ print(f'Ola: {name}')
$ print(f'We have this number: {quantite} of laptops')
$
$
$ for i in range(len(name)):
$ welcome(name[i], quantite[i])
#CRUD = list
$ states = ['RJ', 'SP', 'BA', 'GO']
$ cars = ['BMW', 'GM', 'FORD', 'FERRARI']
$ for i in range(len(states)):
$ print(f'{i+1}º State: {states[i]}; ')
$ states.extend(cars)
$ print(states)
#list - Tuple
$ test = ('BMW', 'GM', 'FORD', 'FERRARI') #Tuple equal to list, but is imutable
$ #Spent low memory to execute and more
speed
$
$ for i in test:
$ print(i)
#list - set
$ test = [10, 20, 30, 40, 50]
$ test2 = [10, 20, 30, 60, 70]
$
$ num1 = set(test)
$ num2 = set(test2)
$
$ print(num1 | num2) # Join 2 list in one list
$ print(num1 - num2) # Return the content that have in num1 and not is have in num2
$ print(num1 ^ num2) # Return content that not is equal in both lists
$ print(num1 & num2) # eturn content that is equal in both lists
#Lambda Function
$ somar10 = lambda x,y: x + y + 10
$ print(somar10(2, 4))
#List - map - running list content and execute Function to each content
$ list1 = [1, 2, 3, 4]
$
$ def muli(x):
$ return x * 2
$
$ list2 = map(muli, list1)
$
$ print(list(list2))
$ print(list(map(lambda x: x * 2, list1)))
#List - filter
$ list1 = [1, 2, 3, 4]
$
$ def remover20(x):
$ return x > 20
$
$ print(list(map(remover20, list1))) # Return false
$ print(list(filter(remover20, list1))) # Return value