Skip to content

Instantly share code, notes, and snippets.

@analistacarlosh
Last active July 22, 2018 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save analistacarlosh/a47bb122f3d0de6bf40cad0c73707db2 to your computer and use it in GitHub Desktop.
Save analistacarlosh/a47bb122f3d0de6bf40cad0c73707db2 to your computer and use it in GitHub Desktop.
#
*Simple and flexibel;
*Python3 was adoption at 2014, the 3.4 version is the most popular;
*Data manipulation;
#The language:
Interpretada de alto nível e que suporta múltiplos paradigmas de programação: imperativo, orientado a objetos e funcional;
Tipagem dinâmica e forte, escopo léxico e gerenciamento automático de memória;
Algumas estruturas de dados embutidas na sintaxe – como tuplas, listas e dicionários;
Com mais prática, elementos mais complexos – como comprehensions, lambdas, packing e unpacking de argumentos.
A comunidade Python preza muito pela legibilidade do código e possui dois elementos que reforçam ainda mais essa questão: PEP-8 e The Zen of Python.
*Language partners
PEP-8 e The Zen of Python.
Apesar de ser uma linguagem interpretada, existe um processo de compilação transparente que transforma o código texto em bytecode, que, por sua vez, é interpretado por uma virtual machine (VM). A implementação padrão da linguagem Python é chamada de CPython
*PEP-8
Use 4 espaços para indentação;
Nunca misture Tabs e espaços;
Tamanho máximo de linha é 79 caracteres;
lower_case_with_underscore para nomes de variáveis;
CamelCase para classes.
reference: http://www.python.org/dev/peps/pep-0008/.
#Pythons 2 and 3
- Em Python 2, strings e bytes são um (e o mesmo) tipo, enquanto unicode é um outro. Já no Python 3, strings são unicodes e os bytes são outro tipo.
- Python 3 has just the int that is like long on Python 2;
- Python 3 - has new modules - statistics, asyncio;
#Compiler
CPython and PyPy
http://python.org
#comand line
python3
check the Ipython
default interpetrador: CPython;
### NUmbers and String
Numbers types:
int:
to create a int type use the int('1')
float:
to create a float type use the float('2.5')
float('+nan')
complex:
complex(1,2)
No pyton2 there were the int and long type, but on Python3 just the int as long
https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex
###Operators:
+ - / *
X//y (division with out franction)
X%y (Mod. the remainde after dividing);
x**y Exponentiation;
Percent
ninetyPercent = 0.90 * 200
print(ninetyPercent)
# result is 180
### Bit operators
???
Operações misturando tipos diferentes e as regras de coerção:
Como Python é uma linguagem dinâmica, muitos programas podem operar números de tipos diferentes em uma mesma operação;
>>> type(1 + 2.0)
<class 'float'>
isinstace(obj, class)
### String
no exist char type just string type;
len("string")
st = "maracana"
st[0:2]
st[2:6]
string functions:
x in y;
x not in y;
x + t (concat);
x * y (repetion);
Strings são sequências imutáveis
>>> minha_str = "livro python 3"
>>> minha_str = minha_str.replace("3", "2")
>>> minha_str
http://docs.python.org/3.3/library/stdtypes.html#string-methods
Alguns muito comuns são: capitalize , count , endswith ,
join , split , startswith e replace
#####
Em Python, podemos interpolar strings usando % ou a função .format() .
Python também implementa o formato printf
http://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting
https://docs.python.org/3/library/string.html#formatstrings
*Compair operators
is the same of another language;
salario = int(input('Salario? '))
print("Valor real: {0}".format(salario - (salario * (imposto * 0.01))))
* if not imposto:
* elfi
*else
###Logic operators
and; or; not;
array/list [1, 2, 3, 4, 5]
*function use the
def
def salario_descontado_imposto(salario, imposto=27.):
return salario - (salario * imposto * 0.01)
### packing
***Data structure
Metadata and data
#Dictionay = map or array
on python (dict)
entidades = {
'Instituicao': []
}
entidades = dict(Instituicao=[])
del entidades['Empreendimento']
to remove the position;
List files of dir
>>> for meta_file in os.listdir('data/meta-data'):
... print(meta_file)
https://www.zerotosingularity.com/blog/downloading-datasets-introducting-pdl/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment