Por que

Python

?

?

Kivy

# Tipo numérico

x = 10
y = 2.5
x * y
# 25.0


# Tipo string

a = 'hello'
b = "world"
print(a + ' ' + b)
# hello world

print(a[0])
# h
print(b[:3])
# hel

# Tipo lista

lista = [1, 2, '3', [4, '5']]
lista[1] # 1
lista[2:] # [2, '3', [4, '5']]
lista[3] # [4, '5']

len(lista) # ?

# count, extend, insert, remove, sort,
# count, index, pop, reverse
# Tipo dicionário

d = {
  'chave 1': 'valor 1',
  'chave 2': 'valor 2',
  'chave 3': ['valores 3.1', 3.2, 4],
  'chave 4': {
      'subchave 1': 1,
      'subchave 2': 2
  }
}

# clear, copy, get, has_key, items, keys, pop, ...
# Funções

def foo():
  return 'bar'
  
def foo2(nome):
  return 'bar, ' + nome
  
def foo3(nome='bar')
  return nome
  
# Funções podem ou não retornar algum valor
#  if/else

x = 10

if x > 5:
  print('%s > 5' % x)
elif x < 5:
  print('%s < 5' % x)
else:
  print('%s == 5' % x)
# for

lista = [10, 20, 30, 40, 50]
for item in lista:
  print(item)
  
# 10
# 20
# 30
# 40
# 50
# while

x = 10

while x > 1:
  print(x)
  x -= 1

# 10
# 9
# 8
# 7
# 6
# 5
# 4
# 3
# 2

Por que Python?

By Marco Rougeth

Por que Python?

  • 933