Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Python Introduction Workshop

Python Introduction Workshop

An introductory workshop to the Python programming language

Avatar for Hugo Gonçalves

Hugo Gonçalves

October 26, 2016

Other Decks in Programming

Transcript

  1. bureaucracy - the boring part 3 • Created by Guido

    Van Rossum, a dutch developer • Developed by Python Software Foundation • First appearance in 20 February 1991 • Free and Open-source with community based development • Most common uses: ◦ Scripting ◦ Small programs ◦ Web (Django, Flask, Wagtail, …)
  2. • multiparadigm - imperative, functional, OO, … • memory management

    built-in • dynamic types and indentation aware • versions matter! Python2.* != Python3 • Python3 isn’t backwards compatible, for instance: ◦ bunch of new reserved methods ◦ syntax changes on print, exception handling and others. ◦ input() function always returns str values in py3 bureaucracy - boring but kind of important 4 More info: http://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html
  3. • Python is based on following philosophy: ◦ Beautiful is

    better than ugly ◦ Explicit is better than implicit ◦ Simple is better than complex ◦ Complex is better than complicated ◦ Readability counts • A consenting adults language • Designed to be highly extensive ◦ Small core, big standard library the pythonic ideals or why I <3 Python 5
  4. syntax & semantic - data types/structures 7 types: • numerical

    ◦ int ◦ float • booleans • no value structures: • tuples • lists • dictionaries (dict)
  5. syntax & semantic - indentation 9 • python uses indentation

    (white space) to know where code blocks end • a block with no code is represented with the keyword pass …. ….…. ….….….
  6. syntax & semantic - flow control 10 • like any

    other language python uses if, elif and else as conditional expressions • if and elif are followed by the logical condition between parenthesis ( )
  7. syntax & semantic - loops 11 • the usual looping

    instruction used is for and can be used to ◦ iterate through elements ◦ iterate through a range • while (looping condition): is also available as a loop mechanism
  8. syntax & semantic - I/O 12 • input and output

    can be done with resource to the module io • for instance, getting input from the user is done using input(“input request string”)
  9. syntax & semantic - slicing 13 • slicing is one

    of the most pythonic things to use • just_a_list[1:9:2] represents the list elements from the index 1 to index 9, with step 2
  10. • dictionaries, dicts for short, are the most used python

    structure • equivalent of maps in the sense of mapping a value to a key • similar to Json objects syntax & semantic - dictionaries (dicts) 14 Dicts API: https://www.tutorialspoint.com/python/python_dictionary.htm
  11. syntax & semantic - functions 15 • functions are declared

    with the def function_name (arguments=default_value): • a function may or may not return something • to return something, the return statement is used
  12. syntax & semantic - other stuff 16 • Imports can

    be to a full module • Or to specific content within a module • Content within a module is accessed through module_name.content_name
  13. • Text Editor ◦ VIM/VI ◦ Atom ◦ Sublime •

    Python3 • Google (trust me) exercises - what you’ll need 18 That’s about it ! :D Python3 online: https://repl.it/languages/python3
  14. • Write a script that: ◦ Reads two numbers ◦

    Adds them ◦ Prints the result Comeonnnnnnnnnn :bored: exercises - I/O 20
  15. • Write a script that: ◦ Reads a number from

    the user ◦ Tries to the given number in this list: [1, 2, 314, 69, 666, 7, 10, 5, 13] Still easy, right? exercises - find a number in a list 21
  16. • write a script that: ◦ sums the even numbers

    until 1000 ◦ sums the odd numbers until 1000 ◦ prints the results exercises - sum evens and odds until 1000 22