Python Overview pt. 1
Ricardo Lapa Dani
Who am I?
• Ricardo Lapa Dani
• Pythonista since 2005
• Djangonaut
• Developer at Horizonte/Globosat
Rio de Janeiro – Brazil
• Free software enthusiast
About python
• Created by Guido Van Rossum
1991
• Free software / Open Source
• Widely used worldwide
• High-level script programming language
• Multi paradigm (procedural, functional,
object-oriented)
• General purpose (web, science, games, gui,
3d, mobile, etc..)
• Multi plataform (windows, linux, etc)
The ZEN of python
• Beautiful is better than ugly
• Explicit is better than implict
• Simple is better than complex
• Complex is better than complicated
• Readability counts.
The python interpreter
• Interactive interface to python
» python
ricardodani@MAC019214
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build
2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 1 + 1
2
>>> 3*(7+2)
27
>>>
The python interpreter
• IDLE in Windows
Running python
programs
• Unix
% python filename.py
• Windows
C:Python> python.exe filename.py
Simple code sample
Language
Characteristics
Types
Integers:
10 20 -1 0 7 42 int(30) int(‘2’)
Float:
1.2 -4.3 5.2 float(10) 5.
Complex
5+7j -2+3j
Strings
‘Ricardo’ “Ricardo” ‘’’Ricardo’’’ u’Ricardo’
Lists
[1, 2, 4, 5, “Ricardo”, 1.2, [2, 4, 5]]
Dictionaries
{‘name’: Ricardo, ‘age’: 25, ‘friends_name’: [“Joaquim”, “Maria”]}
Comparation
1 == 2 False
1 == 1 True
1 in [1, 2, 4, 5] True
not 1 in [1, 2, 4, 5] False
“Lapa” in “Ricardo Lapa” True
1 > 2 False
1 <= 2 True
1 is (2 – 1) True
1 is True False
Logical operators
Arithmetic Operators
+
-
*
/
%
**
//
Comparasion Operators
==
!=
<>
>
<
>=
<=
Logical
and
or
not
Assignment Operators
=
+=
-=
*=
/=
%=
**=
//=
Membership Operators
in
not in
Identify Operators
is
is not
Condictional structures
IF / ELSE / ELIF
if <condition>:
do something
elif <another_condition>:
do another something
else:
do something else
Repetition Structures
For
for <element> in <iterable>:
iterate over each <element> of iterable
While
while <condition_is_true>:
do something
Source
• http://www.slideshare.net/amiable_indian/introduction-to-python
• http://en.wikipedia.org/wiki/Python_(programming_language)
• http://www.tutorialspoint.com/python/python_basic_operators.htm

Python