SlideShare a Scribd company logo
1 of 6
Download to read offline
Untitled0                                       http://127.0.0.1:8888/27ec8dbc-329f-4d46-87e9-5d085a...


         In [1]: a = 'bonjour calvix'


         In [2]: print a

                  bonjour calvix

         In [3]: a='bonjour'


         In [4]: a = "bonjour"


         In [5]: a

         Out[5]: 'bonjour'


         In [6]: a= 42


         In [7]: print a

                  42

         In [8]: a = 10
                 b = 20
                 c = a + b



         In [9]: print c

                  30

         In [10]: 3*4

         Out[10]: 12


         In [11]: 3-2

         Out[11]: 1


         In [12]: 4/2

         Out[12]: 2


         In [13]: 5/2

         Out[13]: 2


         In [14]: 5.0/2

         Out[14]: 2.5


         In [16]: type(10)

         Out[16]: int


         In [17]: type(10.0)

         Out[17]: float


         In [18]: type('blabla')

         Out[18]: str


         In [19]: 10,5

         Out[19]: (10, 5)


         In [21]: # operateurs classique +-=/


         In [23]: 5%2

         Out[23]: 1




1 of 6                                                                                13/01/2012 22:09
Untitled0                                                                     http://127.0.0.1:8888/27ec8dbc-329f-4d46-87e9-5d085a...


         In [26]: 'foo    ' + 'b a r'

         Out[26]: 'foo    b a r'


         In [28]: 'foo' + 10

                  ---------------------------------------------------------------------------
                  TypeError                                 Traceback (most recent call last)
                  /home/nicolas/<ipython-input-28-89215d4a8e7f> in <module>()
                  ----> 1 'foo' + 10

                  TypeError: cannot concatenate 'str' and 'int' objects



         In [30]: 'foo' + '10'

         Out[30]: 'foo10'


         In [32]: 'foo' + str(10)

         Out[32]: 'foo10'


         In [35]: 'foo' * 5

         Out[35]: 'foofoofoofoofoo'


         In [37]: prenom = 'nicolas'
                  'bonjour, %s' % prenom


         Out[37]: 'bonjour, nicolas'


         In [39]: 'bonjour, {}'.format(prenom)

         Out[39]: 'bonjour, nicolas'


         In [40]: # Boolene


         In [41]: True #False

         Out[41]: True


         In [42]: b = [29, 'foo', a]


         In [44]: b

         Out[44]: [29, 'foo', 10]


         In [46]: b[1]

         Out[46]: 'foo'


         In [48]: b[1] = 42


         In [49]: print b

                  [29, 42, 10]

         In [50]: b[5]

                  ---------------------------------------------------------------------------
                  IndexError                                Traceback (most recent call last)
                  /home/nicolas/<ipython-input-50-ca5d543a082a> in <module>()
                  ----> 1 b[5]

                  IndexError: list index out of range




2 of 6                                                                                                              13/01/2012 22:09
Untitled0                                                                      http://127.0.0.1:8888/27ec8dbc-329f-4d46-87e9-5d085a...


         In [51]: b[3] = 20

                  ---------------------------------------------------------------------------
                  IndexError                                Traceback (most recent call last)
                  /home/nicolas/<ipython-input-51-f517828affd8> in <module>()
                  ----> 1 b[3] = 20

                  IndexError: list assignment index out of range



         In [52]: b.append('calvix')


         In [53]: print b

                  [29, 42, 10, 'calvix']

         In [54]: len(b)

         Out[54]: 4


         In [55]: b.append(20)


         In [56]: print b

                  [29, 42, 10, 'calvix', 20]

         In [58]: b.append([20, 'linux'])


         In [59]: print b

                  [29, 42, 10, 'calvix', 20, [20, 'linux'], [20, 'linux']]

         In [60]: b.extend([30, 'torvalds'])


         In [61]: print b

                  [29, 42, 10, 'calvix', 20, [20, 'linux'], [20, 'linux'], 30, 'torvalds']

         In [64]: b.count([20, 'linux'])

         Out[64]: 2


         In [67]: print b.pop()

                  [20, 'linux']

         In [68]: # Tuple


         In [70]: a = (20, 'calvix', 30)



         In [71]: print a

                  (20, 'calvix', 30)

         In [72]: a[1] = 'linux'

                  ---------------------------------------------------------------------------
                  TypeError                                 Traceback (most recent call last)
                  /home/nicolas/<ipython-input-72-228477c61ecf> in <module>()
                  ----> 1 a[1] = 'linux'

                  TypeError: 'tuple' object does not support item assignment



         In [73]: 30, 'calvix'

         Out[73]: (30, 'calvix')


         In [74]: 'calvix'

         Out[74]: 'calvix'


         In [75]: a = 'ping'




3 of 6                                                                                                               13/01/2012 22:09
Untitled0                                                                       http://127.0.0.1:8888/27ec8dbc-329f-4d46-87e9-5d085a...


         In [77]: print a[1]

                  i

         In [78]: a[1] = 'o'

                  ---------------------------------------------------------------------------
                  TypeError                                 Traceback (most recent call last)
                  /home/nicolas/<ipython-input-78-a1f251c3625e> in <module>()
                  ----> 1 a[1] = 'o'

                  TypeError: 'str' object does not support item assignment



         In [81]: a = {1: 'un', 2: 'deux', 'linus': 'torvalds', 'GNU': 'RMS'}


         In [82]: a[1]

         Out[82]: 'un'


         In [83]: a[3]

                  ---------------------------------------------------------------------------
                  KeyError                                  Traceback (most recent call last)
                  /home/nicolas/<ipython-input-83-94e7916e7615> in <module>()
                  ----> 1 a[3]

                  KeyError: 3



         In [85]: a['GNU'] = 42


         In [87]: print a

                  {1: 'un', 2: 'deux', 'linus': 'torvalds', 'GNU': 42}

         In [88]: print a['linus']

                  torvalds

         In [89]: conf = {'taille': 30, 'largeur': 20, 'couleur': 'bleu'}


         In [90]: conf['couleur']

         Out[90]: 'bleu'


         In [91]: # affectation de valeur à une variable
                  a = 10


         In [93]: # Comparaison de valeurs
                  a == 12


         Out[93]: False


         In [94]: # > < <= >= == !=


         In [97]: age = 70
                  if age >= 60:
                      print 'vieux'
                  elif age < 20:
                      print 'très jeune'
                  else:
                      print 'jeune'



                  vieux

         In [98]: tableau = ['foo', 'bar', 42]


         In [99]: 'foo' in tableau

         Out[99]: True




4 of 6                                                                                                                13/01/2012 22:09
Untitled0                                                                      http://127.0.0.1:8888/27ec8dbc-329f-4d46-87e9-5d085a...


         In [101]: if 'calvix' in tableau:
                       print 'c'est dans le tableau'
                   else:
                       print 'pas grave'


                  pas grave

         In [102]: for element in tableau:
                       print element

                  foo
                  bar
                  42

         In [105]: for i, item in enumerate(tableau):
                       print i, item

                  0 foo
                  1 bar
                  2 42

         In [106]: for i in range(10):
                       print i

                  0
                  1
                  2
                  3
                  4
                  5
                  6
                  7
                  8
                  9

         In [107]: i=0
                   i += 1


         In [108]: print i

                  1

         In [109]: #équivaut à; i = i + 1


         In [110]: # n'existe pas avec python i++;i--;


         In [114]: i = 0
                   while i < 5:
                       print 'i vaut %s' % i
                       i += 1


                  i   vaut   0
                  i   vaut   1
                  i   vaut   2
                  i   vaut   3
                  i   vaut   4

         In [132]: def bonjour (prenom, age):
                       if age < 0:
                           raise ValueError
                       print 'bonjour %s, j'ai %s ans' % (prenom, str(age))



         In [134]: try:
                       bonjour('nicolas', -10)
                   except ValueError:
                       print 'exception levée'


                  exception levée

         In [139]: def add (a, b):
                       return a+b



         In [140]: add(40, 2)

         Out[140]: 42




5 of 6                                                                                                               13/01/2012 22:09
Untitled0                                                                      http://127.0.0.1:8888/27ec8dbc-329f-4d46-87e9-5d085a...


         In [141]: def valeur(a, b):
                       return a, b


         In [142]: x, y = valeur(20, 30)


         In [143]: print x

                     20

         In [150]: class Point:
                       def __init__(self, x, y):
                           self._valeur= 30
                           self.x = x
                           self.y = y




         In [148]: a = Point(20, 30)



         In [149]: a.x

         Out[149]: 20


         In [151]: a = add


         In [152]: print a

                     <function add at 0x96f7844>

         In [153]: a(3, 5)

         Out[153]: 8


         In [153]:


         In [158]: a = 'UnE PhRase ExeMple'



         In [159]: a.capitalize()

         Out[159]: 'Une phrase exemple'


         In [160]: import string


         In [162]: string.printable

         Out[162]: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&'()*+,-./:;<=>?@[]^_`{|}~ tnrx0bx0c'


          In [ ]:




6 of 6                                                                                                                            13/01/2012 22:09

More Related Content

What's hot

Pybelsberg — Constraint-based Programming in Python
Pybelsberg — Constraint-based Programming in PythonPybelsberg — Constraint-based Programming in Python
Pybelsberg — Constraint-based Programming in PythonChristoph Matthies
 
Being functional in PHP (PHPDay Italy 2016)
Being functional in PHP (PHPDay Italy 2016)Being functional in PHP (PHPDay Italy 2016)
Being functional in PHP (PHPDay Italy 2016)David de Boer
 
The Ring programming language version 1.5.2 book - Part 66 of 181
The Ring programming language version 1.5.2 book - Part 66 of 181The Ring programming language version 1.5.2 book - Part 66 of 181
The Ring programming language version 1.5.2 book - Part 66 of 181Mahmoud Samir Fayed
 
Stupid Awesome Python Tricks
Stupid Awesome Python TricksStupid Awesome Python Tricks
Stupid Awesome Python TricksBryan Helmig
 
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...DevGAMM Conference
 
Intro to programming games with clojure
Intro to programming games with clojureIntro to programming games with clojure
Intro to programming games with clojureJuio Barros
 
MongoDB Analytics
MongoDB AnalyticsMongoDB Analytics
MongoDB Analyticsdatablend
 
Pandas+postgre sql 實作 with code
Pandas+postgre sql 實作 with codePandas+postgre sql 實作 with code
Pandas+postgre sql 實作 with codeTim Hong
 
Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Baruch Sadogursky
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with PythonHan Lee
 
C++ game development with oxygine
C++ game development with oxygineC++ game development with oxygine
C++ game development with oxyginecorehard_by
 
Python basic
Python basic Python basic
Python basic sewoo lee
 
The Ring programming language version 1.5.3 book - Part 69 of 184
The Ring programming language version 1.5.3 book - Part 69 of 184The Ring programming language version 1.5.3 book - Part 69 of 184
The Ring programming language version 1.5.3 book - Part 69 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 46 of 185
The Ring programming language version 1.5.4 book - Part 46 of 185The Ring programming language version 1.5.4 book - Part 46 of 185
The Ring programming language version 1.5.4 book - Part 46 of 185Mahmoud Samir Fayed
 
Programming with GUTs
Programming with GUTsProgramming with GUTs
Programming with GUTsKevlin Henney
 

What's hot (20)

Pybelsberg — Constraint-based Programming in Python
Pybelsberg — Constraint-based Programming in PythonPybelsberg — Constraint-based Programming in Python
Pybelsberg — Constraint-based Programming in Python
 
Being functional in PHP (PHPDay Italy 2016)
Being functional in PHP (PHPDay Italy 2016)Being functional in PHP (PHPDay Italy 2016)
Being functional in PHP (PHPDay Italy 2016)
 
C++ L04-Array+String
C++ L04-Array+StringC++ L04-Array+String
C++ L04-Array+String
 
EUnit in Practice(Japanese)
EUnit in Practice(Japanese)EUnit in Practice(Japanese)
EUnit in Practice(Japanese)
 
The Ring programming language version 1.5.2 book - Part 66 of 181
The Ring programming language version 1.5.2 book - Part 66 of 181The Ring programming language version 1.5.2 book - Part 66 of 181
The Ring programming language version 1.5.2 book - Part 66 of 181
 
Stupid Awesome Python Tricks
Stupid Awesome Python TricksStupid Awesome Python Tricks
Stupid Awesome Python Tricks
 
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
Самые вкусные баги из игрового кода: как ошибаются наши коллеги-программисты ...
 
Intro to programming games with clojure
Intro to programming games with clojureIntro to programming games with clojure
Intro to programming games with clojure
 
PHP 5.4
PHP 5.4PHP 5.4
PHP 5.4
 
C++ L06-Pointers
C++ L06-PointersC++ L06-Pointers
C++ L06-Pointers
 
MongoDB Analytics
MongoDB AnalyticsMongoDB Analytics
MongoDB Analytics
 
Pandas+postgre sql 實作 with code
Pandas+postgre sql 實作 with codePandas+postgre sql 實作 with code
Pandas+postgre sql 實作 with code
 
Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with Python
 
C++ game development with oxygine
C++ game development with oxygineC++ game development with oxygine
C++ game development with oxygine
 
Python basic
Python basic Python basic
Python basic
 
The Ring programming language version 1.5.3 book - Part 69 of 184
The Ring programming language version 1.5.3 book - Part 69 of 184The Ring programming language version 1.5.3 book - Part 69 of 184
The Ring programming language version 1.5.3 book - Part 69 of 184
 
The Ring programming language version 1.5.4 book - Part 46 of 185
The Ring programming language version 1.5.4 book - Part 46 of 185The Ring programming language version 1.5.4 book - Part 46 of 185
The Ring programming language version 1.5.4 book - Part 46 of 185
 
Programming with GUTs
Programming with GUTsProgramming with GUTs
Programming with GUTs
 
C++ L11-Polymorphism
C++ L11-PolymorphismC++ L11-Polymorphism
C++ L11-Polymorphism
 

Viewers also liked

Brainstorm accommodatie 2011
Brainstorm accommodatie 2011Brainstorm accommodatie 2011
Brainstorm accommodatie 2011SanderKamp
 
Presentacion informatica
Presentacion informaticaPresentacion informatica
Presentacion informaticamarianella1994
 
ამერიკული რევოლუცია
ამერიკული რევოლუციაამერიკული რევოლუცია
ამერიკული რევოლუციაgiorgidobrev
 
Presentacion informatica
Presentacion informaticaPresentacion informatica
Presentacion informaticamarianella1994
 
Analysis of camarines_sur_governance
Analysis of camarines_sur_governanceAnalysis of camarines_sur_governance
Analysis of camarines_sur_governanceduwangcamarines
 
ACTIVITY_REPORT
ACTIVITY_REPORTACTIVITY_REPORT
ACTIVITY_REPORTrony244
 
Arguments for a_new_province
Arguments for a_new_provinceArguments for a_new_province
Arguments for a_new_provinceduwangcamarines
 
Creative Portfolio
Creative PortfolioCreative Portfolio
Creative Portfoliodmisconish
 
Presentation Design Promo
Presentation Design PromoPresentation Design Promo
Presentation Design Promodmisconish
 
Visual Thinking Talk
Visual Thinking TalkVisual Thinking Talk
Visual Thinking Talkdmisconish
 

Viewers also liked (17)

Bmw
BmwBmw
Bmw
 
Brainstorm accommodatie 2011
Brainstorm accommodatie 2011Brainstorm accommodatie 2011
Brainstorm accommodatie 2011
 
Presentacion informatica
Presentacion informaticaPresentacion informatica
Presentacion informatica
 
ამერიკული რევოლუცია
ამერიკული რევოლუციაამერიკული რევოლუცია
ამერიკული რევოლუცია
 
Angles halloween
Angles halloweenAngles halloween
Angles halloween
 
Presentacion informatica
Presentacion informaticaPresentacion informatica
Presentacion informatica
 
Nc for senate dec2
Nc for senate dec2Nc for senate dec2
Nc for senate dec2
 
K.lang
K.langK.lang
K.lang
 
Analysis of camarines_sur_governance
Analysis of camarines_sur_governanceAnalysis of camarines_sur_governance
Analysis of camarines_sur_governance
 
Hb4820
Hb4820Hb4820
Hb4820
 
ACTIVITY_REPORT
ACTIVITY_REPORTACTIVITY_REPORT
ACTIVITY_REPORT
 
Provincial data
Provincial dataProvincial data
Provincial data
 
Arguments for a_new_province
Arguments for a_new_provinceArguments for a_new_province
Arguments for a_new_province
 
Consultations
ConsultationsConsultations
Consultations
 
Creative Portfolio
Creative PortfolioCreative Portfolio
Creative Portfolio
 
Presentation Design Promo
Presentation Design PromoPresentation Design Promo
Presentation Design Promo
 
Visual Thinking Talk
Visual Thinking TalkVisual Thinking Talk
Visual Thinking Talk
 

Similar to Python basics intro with variables, data types, operators, control flow and functions

A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsMichael Pirnat
 
Palestra sobre Collections com Python
Palestra sobre Collections com PythonPalestra sobre Collections com Python
Palestra sobre Collections com Pythonpugpe
 
You are task to add a yawning detection to the programme below;i.pdf
You are task to add a yawning detection to the programme below;i.pdfYou are task to add a yawning detection to the programme below;i.pdf
You are task to add a yawning detection to the programme below;i.pdfsales223546
 
OpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer DisastersOpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer DisastersConnor McDonald
 
{- Do not change the skeleton code! The point of this assign.pdf
{-      Do not change the skeleton code! The point of this      assign.pdf{-      Do not change the skeleton code! The point of this      assign.pdf
{- Do not change the skeleton code! The point of this assign.pdfatul2867
 
Time Series Analysis and Mining with R
Time Series Analysis and Mining with RTime Series Analysis and Mining with R
Time Series Analysis and Mining with RYanchang Zhao
 
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...akaptur
 
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonByterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonakaptur
 
The Ring programming language version 1.5.2 book - Part 45 of 181
The Ring programming language version 1.5.2 book - Part 45 of 181The Ring programming language version 1.5.2 book - Part 45 of 181
The Ring programming language version 1.5.2 book - Part 45 of 181Mahmoud Samir Fayed
 
Literary Genre MatrixPart 1 Matrix FictionNon-fiction.docx
Literary Genre MatrixPart 1 Matrix FictionNon-fiction.docxLiterary Genre MatrixPart 1 Matrix FictionNon-fiction.docx
Literary Genre MatrixPart 1 Matrix FictionNon-fiction.docxjeremylockett77
 
funwithalgorithms.pptx
funwithalgorithms.pptxfunwithalgorithms.pptx
funwithalgorithms.pptxTess Ferrandez
 

Similar to Python basics intro with variables, data types, operators, control flow and functions (20)

Python From Scratch (1).pdf
Python From Scratch  (1).pdfPython From Scratch  (1).pdf
Python From Scratch (1).pdf
 
Talk Code
Talk CodeTalk Code
Talk Code
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
 
alexnet.pdf
alexnet.pdfalexnet.pdf
alexnet.pdf
 
Palestra sobre Collections com Python
Palestra sobre Collections com PythonPalestra sobre Collections com Python
Palestra sobre Collections com Python
 
You are task to add a yawning detection to the programme below;i.pdf
You are task to add a yawning detection to the programme below;i.pdfYou are task to add a yawning detection to the programme below;i.pdf
You are task to add a yawning detection to the programme below;i.pdf
 
OpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer DisastersOpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer Disasters
 
Data types
Data typesData types
Data types
 
Computer Programming- Lecture 9
Computer Programming- Lecture 9Computer Programming- Lecture 9
Computer Programming- Lecture 9
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
{- Do not change the skeleton code! The point of this assign.pdf
{-      Do not change the skeleton code! The point of this      assign.pdf{-      Do not change the skeleton code! The point of this      assign.pdf
{- Do not change the skeleton code! The point of this assign.pdf
 
Time Series Analysis and Mining with R
Time Series Analysis and Mining with RTime Series Analysis and Mining with R
Time Series Analysis and Mining with R
 
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
 
SCIPY-SYMPY.pdf
SCIPY-SYMPY.pdfSCIPY-SYMPY.pdf
SCIPY-SYMPY.pdf
 
Python 1 liners
Python 1 linersPython 1 liners
Python 1 liners
 
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonByterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
 
Python 1
Python 1Python 1
Python 1
 
The Ring programming language version 1.5.2 book - Part 45 of 181
The Ring programming language version 1.5.2 book - Part 45 of 181The Ring programming language version 1.5.2 book - Part 45 of 181
The Ring programming language version 1.5.2 book - Part 45 of 181
 
Literary Genre MatrixPart 1 Matrix FictionNon-fiction.docx
Literary Genre MatrixPart 1 Matrix FictionNon-fiction.docxLiterary Genre MatrixPart 1 Matrix FictionNon-fiction.docx
Literary Genre MatrixPart 1 Matrix FictionNon-fiction.docx
 
funwithalgorithms.pptx
funwithalgorithms.pptxfunwithalgorithms.pptx
funwithalgorithms.pptx
 

Recently uploaded

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 

Recently uploaded (20)

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 

Python basics intro with variables, data types, operators, control flow and functions

  • 1. Untitled0 http://127.0.0.1:8888/27ec8dbc-329f-4d46-87e9-5d085a... In [1]: a = 'bonjour calvix' In [2]: print a bonjour calvix In [3]: a='bonjour' In [4]: a = "bonjour" In [5]: a Out[5]: 'bonjour' In [6]: a= 42 In [7]: print a 42 In [8]: a = 10 b = 20 c = a + b In [9]: print c 30 In [10]: 3*4 Out[10]: 12 In [11]: 3-2 Out[11]: 1 In [12]: 4/2 Out[12]: 2 In [13]: 5/2 Out[13]: 2 In [14]: 5.0/2 Out[14]: 2.5 In [16]: type(10) Out[16]: int In [17]: type(10.0) Out[17]: float In [18]: type('blabla') Out[18]: str In [19]: 10,5 Out[19]: (10, 5) In [21]: # operateurs classique +-=/ In [23]: 5%2 Out[23]: 1 1 of 6 13/01/2012 22:09
  • 2. Untitled0 http://127.0.0.1:8888/27ec8dbc-329f-4d46-87e9-5d085a... In [26]: 'foo ' + 'b a r' Out[26]: 'foo b a r' In [28]: 'foo' + 10 --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /home/nicolas/<ipython-input-28-89215d4a8e7f> in <module>() ----> 1 'foo' + 10 TypeError: cannot concatenate 'str' and 'int' objects In [30]: 'foo' + '10' Out[30]: 'foo10' In [32]: 'foo' + str(10) Out[32]: 'foo10' In [35]: 'foo' * 5 Out[35]: 'foofoofoofoofoo' In [37]: prenom = 'nicolas' 'bonjour, %s' % prenom Out[37]: 'bonjour, nicolas' In [39]: 'bonjour, {}'.format(prenom) Out[39]: 'bonjour, nicolas' In [40]: # Boolene In [41]: True #False Out[41]: True In [42]: b = [29, 'foo', a] In [44]: b Out[44]: [29, 'foo', 10] In [46]: b[1] Out[46]: 'foo' In [48]: b[1] = 42 In [49]: print b [29, 42, 10] In [50]: b[5] --------------------------------------------------------------------------- IndexError Traceback (most recent call last) /home/nicolas/<ipython-input-50-ca5d543a082a> in <module>() ----> 1 b[5] IndexError: list index out of range 2 of 6 13/01/2012 22:09
  • 3. Untitled0 http://127.0.0.1:8888/27ec8dbc-329f-4d46-87e9-5d085a... In [51]: b[3] = 20 --------------------------------------------------------------------------- IndexError Traceback (most recent call last) /home/nicolas/<ipython-input-51-f517828affd8> in <module>() ----> 1 b[3] = 20 IndexError: list assignment index out of range In [52]: b.append('calvix') In [53]: print b [29, 42, 10, 'calvix'] In [54]: len(b) Out[54]: 4 In [55]: b.append(20) In [56]: print b [29, 42, 10, 'calvix', 20] In [58]: b.append([20, 'linux']) In [59]: print b [29, 42, 10, 'calvix', 20, [20, 'linux'], [20, 'linux']] In [60]: b.extend([30, 'torvalds']) In [61]: print b [29, 42, 10, 'calvix', 20, [20, 'linux'], [20, 'linux'], 30, 'torvalds'] In [64]: b.count([20, 'linux']) Out[64]: 2 In [67]: print b.pop() [20, 'linux'] In [68]: # Tuple In [70]: a = (20, 'calvix', 30) In [71]: print a (20, 'calvix', 30) In [72]: a[1] = 'linux' --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /home/nicolas/<ipython-input-72-228477c61ecf> in <module>() ----> 1 a[1] = 'linux' TypeError: 'tuple' object does not support item assignment In [73]: 30, 'calvix' Out[73]: (30, 'calvix') In [74]: 'calvix' Out[74]: 'calvix' In [75]: a = 'ping' 3 of 6 13/01/2012 22:09
  • 4. Untitled0 http://127.0.0.1:8888/27ec8dbc-329f-4d46-87e9-5d085a... In [77]: print a[1] i In [78]: a[1] = 'o' --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /home/nicolas/<ipython-input-78-a1f251c3625e> in <module>() ----> 1 a[1] = 'o' TypeError: 'str' object does not support item assignment In [81]: a = {1: 'un', 2: 'deux', 'linus': 'torvalds', 'GNU': 'RMS'} In [82]: a[1] Out[82]: 'un' In [83]: a[3] --------------------------------------------------------------------------- KeyError Traceback (most recent call last) /home/nicolas/<ipython-input-83-94e7916e7615> in <module>() ----> 1 a[3] KeyError: 3 In [85]: a['GNU'] = 42 In [87]: print a {1: 'un', 2: 'deux', 'linus': 'torvalds', 'GNU': 42} In [88]: print a['linus'] torvalds In [89]: conf = {'taille': 30, 'largeur': 20, 'couleur': 'bleu'} In [90]: conf['couleur'] Out[90]: 'bleu' In [91]: # affectation de valeur à une variable a = 10 In [93]: # Comparaison de valeurs a == 12 Out[93]: False In [94]: # > < <= >= == != In [97]: age = 70 if age >= 60: print 'vieux' elif age < 20: print 'très jeune' else: print 'jeune' vieux In [98]: tableau = ['foo', 'bar', 42] In [99]: 'foo' in tableau Out[99]: True 4 of 6 13/01/2012 22:09
  • 5. Untitled0 http://127.0.0.1:8888/27ec8dbc-329f-4d46-87e9-5d085a... In [101]: if 'calvix' in tableau: print 'c'est dans le tableau' else: print 'pas grave' pas grave In [102]: for element in tableau: print element foo bar 42 In [105]: for i, item in enumerate(tableau): print i, item 0 foo 1 bar 2 42 In [106]: for i in range(10): print i 0 1 2 3 4 5 6 7 8 9 In [107]: i=0 i += 1 In [108]: print i 1 In [109]: #équivaut à; i = i + 1 In [110]: # n'existe pas avec python i++;i--; In [114]: i = 0 while i < 5: print 'i vaut %s' % i i += 1 i vaut 0 i vaut 1 i vaut 2 i vaut 3 i vaut 4 In [132]: def bonjour (prenom, age): if age < 0: raise ValueError print 'bonjour %s, j'ai %s ans' % (prenom, str(age)) In [134]: try: bonjour('nicolas', -10) except ValueError: print 'exception levée' exception levée In [139]: def add (a, b): return a+b In [140]: add(40, 2) Out[140]: 42 5 of 6 13/01/2012 22:09
  • 6. Untitled0 http://127.0.0.1:8888/27ec8dbc-329f-4d46-87e9-5d085a... In [141]: def valeur(a, b): return a, b In [142]: x, y = valeur(20, 30) In [143]: print x 20 In [150]: class Point: def __init__(self, x, y): self._valeur= 30 self.x = x self.y = y In [148]: a = Point(20, 30) In [149]: a.x Out[149]: 20 In [151]: a = add In [152]: print a <function add at 0x96f7844> In [153]: a(3, 5) Out[153]: 8 In [153]: In [158]: a = 'UnE PhRase ExeMple' In [159]: a.capitalize() Out[159]: 'Une phrase exemple' In [160]: import string In [162]: string.printable Out[162]: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&'()*+,-./:;<=>?@[]^_`{|}~ tnrx0bx0c' In [ ]: 6 of 6 13/01/2012 22:09