Você está na página 1de 5

#Formatter string

$ text2 = f'O {name} {Last_Name} e um excelente [{Profession}]'


$ print(menssage.upper()) #Upper case all letters
$ print(menssage.capitalize()) #First letter of all word be upperCase
$ print(menssage.find('adoro')) #Will find the letter or world and return position
$ print(menssage.replace('caseira', 'de rua')) #Replace the letter or world
$ print(menssage.strip()) #Remove all spaces before start text

#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')

#For loop - Int


$ for number in range(5):
$ print(number)

#For loop - String


$ for letter in 'Google':
$ print(letter)

#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])

#Function + Global Variable


$ def custonmer1(name):
$ print(f'Ola {name}')
$
$ def custonmer2(name):
$ return(f'Ola {name}')
$
$ x = custonmer1('Maria')
$ y = custonmer2('Jose')
$
$ print(x)
$ print(y)

#Function + ReUse Variable - xargs


$ def sum(*numbers):
$ result = 0
$ for i in numbers:
$ result = result + i
$ return result
$
$ x = sum(2,4,8,6)
$ print(x)

#CRUD = list
$ states = ['RJ', 'SP', 'BA', 'GO']
$ cars = ['BMW', 'GM', 'FORD', 'FERRARI']

$ states.append('DF') # Addition content in last item in list


$ states.remove('BA') # Remove content informate
$ states.insert(1, 'SC') # Addition content in locate informate
$ states.pop(0) # Remove content in position informate
$ states.sort() # Organize the list in order

$ for i in range(len(states)):
$ print(f'{i+1}º State: {states[i]}; ')

$ states.extend(cars)
$ print(states)

#list - list inside list


$ itens = [
$ ['a','b'],
$ [1,2]
$ ]
$ print(itens[1][0])

#list - Extract content in Variable


$ cars = ['BMW', 'GM', 'FORD', 'FERRARI']$
$ car1, car2, *car3 = cars$
$ print(car1)
$ print(car2)
$ print(car3)

#list - Valid content inside list


$ color_customer=input('Inform color: ')
$ colors = ['yellow', 'green', 'blue', 'red']
$
$ if color_customer.lower() in colors:
$ print(f'We have this color: {color_customer}')
$ else:
$ print('Not have this color')

#list - Joi two lists


$ var = list('batata') #Create a list
$ print(var)
$
$ colors = ['yellow', 'green', 'blue', 'red']
$ cars = ['BMW', 'GM', 'FORD', 'FERRARI']
$
$ two_list = zip(colors, cars)
$
$ print(list(two_list)) #join two lists

#list - Create list from string


$ fruits_customer = input('Inform the fruits name separeted by comma: ')
$
$ fruits_list = fruits_customer.split(', ')
$
$ print(fruits_list)

#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

#list - set CRUD


$ s1 = {1, 2, 3, 4, 5, 6}
$ s1.add(7) #Addition new contet
$ s1.update([7, 8, 9]) #Addition a lot of new contet
$ s1.discard(90) #Remove content informate but not execute error if case
not found content
$ s1.remove(90) #Remove content informate but execute error if case not
found content
$
$ print(s1)
#list - Dictionary
$ class_match = {
$ 'name' : 'Ana',
$ 'age': 21,
$ 'approve': True,
$ 'subjects': ['Math', 'Portuguese', 'English']}
$
$ class_match.update({'adress': 'Street B'}) #Addition new information
$
$ del class_match['age'] #Delete new information
$
$ print(class_match.get('subjects', 'Not found')) #Get value and if case not found,
execute a mensage
$
$ print(class_match.items()) #Get items
$
$ print(class_match.keys()) #Get keys
$
$ print(class_match.values()) #Get value
$
$ for keys, values in class_match.items():
$ print(keys)

#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

#list - filter and addition content in other list


$ test = ('BMW', 'GM', 'FORD', 'FERRARI') #Tuple equal to array, but is imutable
$
$ test2 = [i for i in test if 'B' in i]
$
$ print(test2)

#list - Create list automatic


$ values = [x * 10 for x in range(6)]
$
$ print(values)
#Try - Cath
$ try:
$ letter = ['a', 'b', 'c']
$ print(letter[3])
$ except IndexError: # Execute if try was false
$ print('Index not found')
$ else: # Execute if try was true
$ print('teste')
$ finally: # Execute every time
$ print('finally')

Você também pode gostar