Basics of Programming in Python

Introduction

16.09.2022

Course Overview

Basics of Programming in Python is an 8-week compulsory course aimed at social science students to learn programming skills for their research.

Schedule

  • 1st module: doubled classes on Friday and Saturday until 08.10
  • 2nd module: ¯\_(ツ)_/¯
  • there will be a big Homework Assignment between modules

Assessment

0.25 * Weekly Quizes

0.25 * Homework Assigment

0.5 * Final Exam


The exam is very much tied to the course material,
so it is recommended to attend classes
🙃

Communication

biba i boba

Communication

Telegram channel with chat -> to discuss and be informed

My email: alexpoov99@gmail.com

  • doublecheck whether your question was already asked
  • please be ethical: do not text me late at night
  • sign your letters and determine their subject, otherwise I may not answer
qr code to telegram channel

Let's talk about Python, baby.

Python in the wider context

  • Python is very popular.
  • Python is versatile.
  • Python is very concise.
stackoverflow survey
stackoverflow survey

Python is free and open-source language

  • You can take a look at source code of Python (Python and C) here.
  • And even contribute!
stackoverflow survey

Python is a high-level language

Every computer program interacts with very low-level components of computer - memory in bytes (0,1).

However, for the sake of convenience, time-saving and ease, this interaction has been abstracted away by multiple layers

The beauty of it is that you do not have to know much about this interaction to become a good python programmer.

This is because logical units of python are mere abstractions: objects instead of computer processor transistors and memory.

Python is a high-level language

Python is an interpreted language

  • It doesn't need to be compiled and can be distributed as plain text files with .py file extension
  • Source code (plaintext .py file) is compiled into bytecode, which is later executed by Python Virtual Machine, but this process is abstracted from the developer.
  • Therefore, python can be run in two ways:
    • interactively (line-by-line)
    • as a complete script
Python is an interpreted language

Python is an object-oriented language

This means that logical units of Python programs are objects.

Objects store together the data and means to process it

  • a practical example: a string objects stores its value as way as methods to manipulate it (example below)

Please do not antagonize functional vs. object-oriented programs, because one could be both and paradigms are not exclusive.

Python is an object-oriented language

Because Python is very flexible, so you can make your code be both:

  • imperative and object-oriented (e.g. have a set of consecutive instructions but use objects)
  • functional and object-oriented (e.g. have objects with pure functions)

Python is a language with dynamic semantics

Python objects are dynamic because they are not strictly typed.

In languages such as Java, C, or C++, you initialize a variable with a pre-defined type.

But in Python, the type of object is determined in runtime.

Python is a very versatile language and can do:

  • systems programming (built-in libraries allow access to the operating system)
  • APIs (application programming interfaces), e.g. means of communication between programs
  • internet scripting: parsing websites, back-end and front-end web-development
  • scientific programming: data analysis, data visualisation, machine learning...
  • working with databases and data engineering
  • game projects, mobile apps, networks, etc.
an example of social networks analysis in python
an example of music tastes analysis in python
an example of web applications in python

Python is a language with great and extensive documentation

link

In case you have any question, please, consult with it first, and only afterwards go to Google and forums like StackOverflow.

What to Read?

Where to Code?

There is two extensions you need to know:

  • .py is a regular Python file with your code only.
  • .ipynb is a Python notebook, which output shows in readable format.
    • There is code blocks (or chunks).
    • There is also Markdown (lightweight markup language for creating formatted text) chunks.

Where to Code?

Some places where you can edit Python files:

  • Terminal (?)
  • Jupyter Notebook (an open-source application to edit .ipynb files, imo it's great for beginners)
  • Specific platforms like Colab, Deepnote, Gradient, etc.
  • Installed Integrated development environment (IDE): Visual Studio Code, PyCharm, Atom...
colab view
jupyter notebook view
visual studio code view

Questions?