Este notebook de jupyter te permite comprender los principios basicos de la sintaxis que utiliza Python
Por el momento el codigo no contiene ningun tipo de explicacion
In [6]:
1 + 1
Out[6]:
In [7]:
1 * 3
Out[7]:
In [8]:
1 / 2
Out[8]:
In [9]:
2 ** 4
Out[9]:
In [10]:
4 % 2
Out[10]:
In [11]:
5 % 2
Out[11]:
In [12]:
(2 + 3) * (5 + 5)
Out[12]:
In [1]:
# No pueden comenzar con numero o un caracter especial
name_of_var = 2
In [2]:
x = 2
y = 3
In [3]:
z = x + y
In [4]:
z
Out[4]:
In [5]:
'single quotes'
Out[5]:
In [6]:
"double quotes"
Out[6]:
In [7]:
" wrap lot's of other quotes"
Out[7]:
In [8]:
x = 'hello'
In [9]:
x
Out[9]:
In [10]:
print(x)
In [11]:
num = 12
name = 'Sam'
In [12]:
print('My number is: {one}, and my name is: {two}'.format(one=num,two=name))
In [13]:
print('My number is: {}, and my name is: {}'.format(num,name))
In [26]:
[1,2,3]
Out[26]:
In [27]:
['hi',1,[1,2]]
Out[27]:
In [28]:
my_list = ['a','b','c']
In [29]:
my_list.append('d')
In [30]:
my_list
Out[30]:
In [31]:
my_list[0]
Out[31]:
In [32]:
my_list[1]
Out[32]:
In [33]:
my_list[1:]
Out[33]:
In [34]:
my_list[:1]
Out[34]:
In [35]:
my_list[0] = 'NEW'
In [98]:
my_list
Out[98]:
In [99]:
nest = [1,2,3,[4,5,['target']]]
In [100]:
nest[3]
Out[100]:
In [101]:
nest[3][2]
Out[101]:
In [102]:
nest[3][2][0]
Out[102]:
In [37]:
d = {'key1':'item1','key2':'item2'}
In [38]:
d
Out[38]:
In [39]:
d['key1']
Out[39]:
In [40]:
True
Out[40]:
In [41]:
False
Out[41]:
In [42]:
t = (1,2,3)
In [43]:
t[0]
Out[43]:
In [44]:
t[0] = 'NEW'
In [45]:
{1,2,3}
Out[45]:
In [46]:
{1,2,3,1,2,1,2,3,3,3,3,2,2,2,1,1,2}
Out[46]:
In [47]:
1 > 2
Out[47]:
In [48]:
1 < 2
Out[48]:
In [49]:
1 >= 1
Out[49]:
In [50]:
1 <= 4
Out[50]:
In [51]:
1 == 1
Out[51]:
In [52]:
'hi' == 'bye'
Out[52]:
In [53]:
(1 > 2) and (2 < 3)
Out[53]:
In [54]:
(1 > 2) or (2 < 3)
Out[54]:
In [55]:
(1 == 2) or (2 == 3) or (4 == 4)
Out[55]:
In [56]:
if 1 < 2:
print('Yep!')
In [57]:
if 1 < 2:
print('yep!')
In [58]:
if 1 < 2:
print('first')
else:
print('last')
In [59]:
if 1 > 2:
print('first')
else:
print('last')
In [60]:
if 1 == 2:
print('first')
elif 3 == 3:
print('middle')
else:
print('Last')
In [61]:
seq = [1,2,3,4,5]
In [62]:
for item in seq:
print(item)
In [63]:
for item in seq:
print('Yep')
In [64]:
for jelly in seq:
print(jelly+jelly)
In [65]:
i = 1
while i < 5:
print('i is: {}'.format(i))
i = i+1
In [66]:
range(5)
Out[66]:
In [67]:
for i in range(5):
print(i)
In [68]:
list(range(5))
Out[68]:
In [69]:
x = [1,2,3,4]
In [70]:
out = []
for item in x:
out.append(item**2)
print(out)
In [71]:
[item**2 for item in x]
Out[71]:
In [72]:
def my_func(param1='default'):
"""
Docstring goes here.
"""
print(param1)
In [73]:
my_func
Out[73]:
In [74]:
my_func()
In [75]:
my_func('new param')
In [76]:
my_func(param1='new param')
In [77]:
def square(x):
return x**2
In [78]:
out = square(2)
In [79]:
print(out)
In [80]:
def times2(var):
return var*2
In [81]:
times2(2)
Out[81]:
In [82]:
lambda var: var*2
Out[82]:
In [83]:
seq = [1,2,3,4,5]
In [84]:
map(times2,seq)
Out[84]:
In [85]:
list(map(times2,seq))
Out[85]:
In [86]:
list(map(lambda var: var*2,seq))
Out[86]:
In [87]:
filter(lambda item: item%2 == 0,seq)
Out[87]:
In [88]:
list(filter(lambda item: item%2 == 0,seq))
Out[88]:
In [111]:
st = 'hello my name is Sam'
In [112]:
st.lower()
Out[112]:
In [113]:
st.upper()
Out[113]:
In [103]:
st.split()
Out[103]:
In [104]:
tweet = 'Go Sports! #Sports'
In [106]:
tweet.split('#')
Out[106]:
In [107]:
tweet.split('#')[1]
Out[107]:
In [92]:
d
Out[92]:
In [93]:
d.keys()
Out[93]:
In [94]:
d.items()
Out[94]:
In [95]:
lst = [1,2,3]
In [96]:
lst.pop()
Out[96]:
In [108]:
lst
Out[108]:
In [109]:
'x' in [1,2,3]
Out[109]:
In [110]:
'x' in ['x','y','z']
Out[110]: