Skip to content
Snippets Groups Projects
Commit 539009b2 authored by Auke Klazema's avatar Auke Klazema
Browse files

Remove topic list

parent beea916c
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:a1b0abfd-330c-4c9a-81e0-8c996948cf16 tags:
# Introduction to programming in Python
Author: Auke Klazema (klazema@astron.nl)
Length: 2.5 days
%% Cell type:markdown id:785876cb-ef7d-46cf-aa9e-20950b6e8574 tags:
## What is programming?
%% Cell type:markdown id:f8081ed1-9c6b-4c0b-8f10-0cc8fad37a9a tags:
## What is a programming language?
%% Cell type:markdown id:ecf1f80a-3312-4f3c-85c8-6199daad071d tags:
## Python 3 introduction
%% Cell type:markdown id:cf433491-7990-443f-ae1a-3157a09a3c37 tags:
## First working program
Lets start out with a working simple program.
%% Cell type:code id:f3b3fb00-a25e-4050-8d41-ad9a10678bf9 tags:
``` python
#!/bin/env python3
print("Hello World")
```
%% Cell type:markdown id:0fbd93a6-fa1c-4f38-a6e5-99c2ec222c91 tags:
This is a small script / program that outputs the string plus a newline on the standar output.
The first line is the shebang that tells my terminal how to run the program. This way I only have to execute my script and the terminal feeds it into python. An alternative is to run it directly with python like so: python helloworld.py
Then we have a empty line that gets ignored by Python. The last line contains a built-in function called "print" and this function accepts a couple of arguments. In this case I gave it the string "Hello World".
Lets look up the documentation for print.
%% Cell type:code id:6bf448b7-7e4f-46ff-81d8-0b94d97104fe tags:
``` python
#!/bin/env python3
help(print)
```
%% Output
Help on built-in function print in module builtins:
print(...)
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.
%% Cell type:markdown id:6ec87341-5d37-4c12-a849-0ed856c55e67 tags:
The print documentation can also be found on the online documentation at python.org at https://docs.python.org/3/library/functions.html#print
```
print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
Print objects to the text stream file, separated by sep and followed by end. sep, end, file and flush, if present, must be given as keyword arguments.
All non-keyword arguments are converted to strings like str() does and written to the stream, separated by sep and followed by end. Both sep and end must be strings; they can also be None, which means to use the default values. If no objects are given, print() will just write end.
The file argument must be an object with a write(string) method; if it is not present or None, sys.stdout will be used. Since printed arguments are converted to text strings, print() cannot be used with binary mode file objects. For these, use file.write(...) instead.
Whether output is buffered is usually determined by file, but if the flush keyword argument is true, the stream is forcibly flushed.
Changed in version 3.3: Added the flush keyword argument.
```
%% Cell type:markdown id:701d1e4e-fc0a-4164-abac-cc2f49f5c88b tags:
So based on the information given in this first section I could spend days talking. But this is a beginners course on programming. We happen to use Python as our tool of learning so lets get some basics out of the way first. Its fine if not everything is understood from the start because I will revisit them later.
The help text of print talks about values, streams, sys.stdout. It mentions functions, objects and modules. It also mentions optional keywords and strings. We only have 2.5 days so I will need to leave out a lot of things that Python offers. Some will be covered in other courses Astron will give but others will need to be learned through other means.
%% Cell type:markdown id:2babb3aa-8be9-4fe2-8dbc-f3fa8aff2574 tags:
## First broken programs
Your programs will be broken alot, especially in the beginning, so lets see how to deal with that.
%% Cell type:code id:0c656ee3-870f-4f51-aad4-4fd2dbf160b6 tags:
``` python
#!/bin/env python3
print("Hello World")
```
%% Cell type:markdown id:95082acd-7c8b-4138-9189-84af128a0a93 tags:
This program will give a NameError.
%% Cell type:code id:6d99111d-b279-4f22-8862-8c59df632237 tags:
``` python
#!/bin/env python3
printer("Hello World")
```
%% Cell type:markdown id:93564fff-c8c9-4059-89f2-82d29453f28e tags:
This program will give an IndentationError. Indentation is very important in a Python program.
%% Cell type:code id:9fc26361-3d9c-4160-a245-6ef36ff8317f tags:
``` python
#!/bin/env python3
print("Hello World)
```
%% Cell type:markdown id:7b84478e-b8c8-48ad-b6b5-b29d4b21ad3d tags:
This program will give a SyntaxError
%% Cell type:markdown id:4df3af9b-23e2-45c5-82ed-e7deb2b376aa tags:
### Exercise
Try to break your program in more ways.
%% Cell type:markdown id:0823895a-f753-44b2-8f0b-e24b63c3545f tags:
Programming introduction
Programming languages
Installing Python 3
Python 3 introduction
Finding documentation
Your first program
Your first bug
Functions
Variables
Numbers and strings
Basic math
Data types (lists, dictionaries, sets, tuples, etc)
Flow control
Abstraction
How to solve problems with programming
%% Cell type:markdown id:2d5d509d-2735-4ff0-9417-d2969f991958 tags:
## Functions
%% Cell type:markdown id:41925997-1b78-44a5-a336-ae9a2c87960c tags:
## Variables
%% Cell type:markdown id:bb1d80f2-640b-4d80-8fd4-ef310008b3b0 tags:
## Numbers and Strings
%% Cell type:code id:c979d150-9c12-4327-b565-15abe1d1c386 tags:
``` python
#!/bin/env python3
"Hello world"
```
%% Output
'Hello world'
%% Cell type:markdown id:32d8f383-db80-479a-9aab-20cc430e9739 tags:
## Basic math
%% Cell type:markdown id:7c011488-f5dc-4cea-85db-1fa202c2c240 tags:
## Data types
### lists
### dictionaries
### sets
### tuples
%% Cell type:markdown id:13e86fa7-c3ab-45fd-a1c0-876cc51c89c0 tags:
## Flow control
%% Cell type:markdown id:e24b0155-ddec-4363-a111-a9d8b0670fc6 tags:
## Abstraction
%% Cell type:markdown id:02b69029-abb4-417e-8258-46e01502e971 tags:
## How to solve problems with programming
Breaking up and composing
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment