Python🐍 for Poets📚🪶
Introductory Python Сourse for Humanities Researchers
Today:
Live demo 🎥
So what is the downside?
Linear Warriors, Quadratic Wizards (from TV tropes)
Programmers are a typical example of real-life Wizards 🧙
Excel users are more of a Warrior type ⚔️.
Programming languages vs applications (Excel etc.)
Programming languages vs applications (Excel etc.)
vs
Coding gives you more freedom
End of motivational prologue
Now, round of getting to know each other
Some rules and principles of our course
General tip: if you’re stuck while programming try these 😉
If everyone is busy doing something and you are lost:
And now, Python
Installing Python
Launch the built-in development environment (IDLE)
First thing you’re going to see:
This window with a >>> promt is where you can execute python commands in interactive mode. That means that python will automatically print the results of your commands.
👩💻👨💻 Write this:
>>> print('Hello world')
Congrats! You’ve just written a program! You are already a programmer! Keep on going!
By the way, you’ve just learned to use print()
Python as calculator;
Integers
You can always use Python as calculator:
+-* work with numbers just as you’d expect them to work:
👩💻👨💻Try it yourself!
Division is a bit more complicated
Division is a bit more complicated
Variables
Imagine I want to convert my dollars to euros by multiplying them by 1.022946
�Hard to always type it:
Imagine I want to convert my dollars to euros by multiplying them by 1.022946
�Easier to save this number just once under some easy name, like ‘rate’:
Variable
variable
value
assignment
👩💻👨💻 Exercise:
Strings
String (‘str’ in pythonic)
Strings can also be ‘added together’
👩💻👨💻Try it yourself!
Strings can also be ‘added together’ and even ‘multiplied’
👩💻👨💻Try it yourself!
Printing many strings, or strings and integers together (the easiest way):
name = "Jean"
age = 35
bodyweight = 84.3
city = "Marseille"
print(name, "is", age, "years old and lives is in", city, ".")
👩💻👨💻 Exercise:
Useful string methods
.replace() — replaces some things in string
.count() — counts number of occurrences of some string inside a bigger string
Useful string methods
.count() — counts number of occurrences of some string inside a bigger string
More on string methods here
Getting input from user
input() function
👩💻👨💻 Exercise:
Saving files with code
The interactive shell can process only one line (there are exceptions to this rule, but we can ignore them for now)
You can only do it line by line:
Large programs with multiple lines of code are written in a separate file,
not in the interactive shell
How to create in IDLE a file with program:
Cmd + N on Mac:
Ctrl + N on Windows
You’ll see a blank file, like in a simple notepad:
Now type in your code. And that’s already a full-blown program:
👩💻👨💻 Exercise:
Google Colab
(a more useful, collaborative and friendly
coding environment than IDLE)