Girl Develop It is here to provide affordable and accessible programs to learn software through mentorship and hands-on instruction.
Classroom "rules":
This may change if we end up needing more or less time for certain topics.
Tell us about yourself:
Example (that you don't need to understand yet!):
def add_numbers_between(start, end):
sum = 0
for n in range(start, end):
sum += n
return n
add_numbers_between(5, 10)
You can make entirely text-based console (command-line) applications/scripts. These are common for automating tedious/repetitive tasks.
Applications for non-technical users typically include a GUI (graphical user interface).
Web apps are increasingly more popular than downloaded apps. HTML/CSS/JS would be used for the frontend, but Python can be used for the backend of a web application.
Data analysts and data scientists often use notebooks, like Jupyter Notebooks to document and share calculations and outputs.
π¬ What's one thing you'd LOVE to make with Python?
Usually, we would write Python code on our own computers using:
(click the links above for setup info)
Installing/running Python on lots of different systems/versions is tricky.
In this class, we'll use Replit, an online editor.
We use print() to tell Python what to output. This is very useful in debugging - ex, to see the value of a variable.
print("hello world!"
Programs manipulate values.
Each value has a certain data type.
Data type | Example values |
---|---|
Integers | 2 44 -3
|
Floats | 3.14 4.5 -2.0
|
Booleans | True False
|
Strings | 'Β‘hola!' 'its python time!'
|
In Python, objects have names. Different types of objects (variables, functions, etc) can have names.
A variable is a name bound to a value using an assignment statement:
x | = | 7 |
Name | Value |
The value can be any expression:
x | = | 1 + 2 * 3 - 4 // 5 |
Name | Expression |
It can also be a function:
x | = | add(1+2) |
Name | Expression |
Only certain character combinations are allowed:
Allowed names
|
Non-allowed names
|
See more examples at W3Schools: https://www.w3schools.com/python/gloss_python_variable_names.asp
Names are case sensitive.
If name is my_fav_hobby
, the following are not equivalent:
my_fav_hobbY
My_fav_hobby
MY_FAV_HOBBY
myfavhobby
Programming can help you develop an eye for these little details, but software development tools will also help you find these issues.
first_name
rather than fn
m
(variables only)
hobby
my_fav_hobby
See more examples at Real Python: https://realpython.com/python-pep8/#naming-styles
A name can be referenced multiple times:
x = 10
y = 3
result1 = x * y
result2 = x + y
A name that's bound to a data value is also known as a variable.
π¬ How many variables are in that code snippet?
4 variables: x
, y
, result1
, result2
A name can only be bound to a single value.
my_name = 'Liz'
my_name = my_name + 'iz'
π¬ Will that code error? If not, what will my_name
store?
It will not error (similar code in other languages might, however).
The name my_name
is now bound to the value 'Liziz'.
An expression describes a computation and evaluates to a value.
Some expressions use operators:
18 + 69
6/23
2 * 100
2 ** 100
Let's try it in Repl!
Operator | Name | Example |
---|---|---|
+ | Addition | 1 + 2 = 3 |
- | Subtraction | 2 - 1 = 1 |
* | Multiplication | 2 * 3 = 6 |
/ | Division | 6 / 3 = 2 |
% | Modulus (divide & return the remainder) | 5 % 2 = 1 |
** | Exponentation (aka powers) | 2 ** 3 = 8 |
// | Floor division (divide & round down to the nearest integer) | 5 // 2 = 2 |
Many expressions use function calls:
pow(2, 100)
max(50, 300)
min(-1, -300)
Learn more about built-in functions in the Python docs.
Let's try these in Repl!
Expressions with operators can also be expressed with function call notation:
2 ** 100
pow(2, 100)
Some functions from the Python standard library are available by default. Others are included with a basic Python installation, but need to be imported into your current file before they can be used.
Import a single function from the Operator module :
from operator import add
18 + 69
add(18, 69)
Import the entire Operator module (all of its functions):
import operator
18 + 69
add(18, 69)
Why would we import a single function vs an entire module? Some modules are big! You'll get better performance by importing only what you need.
We can combine multiple expression inside one another. These are evaluated from the inside out.
Open Open the Class1Ex1OperatorExpressions repl.
Let's work through these questions together!
Each Python data type has built-in capababilites that are specific to that data type. These are call built-in methods.
Built-in methods use a different syntax from the operators and functions we looked at in the last section:
'blar'.upper()
my_string = 'blar'
my_string.upper()
The Python String data type comes with some handy built-in methods that can be used to manipulate bits of text.
Function | Description |
---|---|
.upper() | Returns a copy of the string with all characters converted to uppercase |
.lower() | Returns a copy of the string with all characters converted to lowercase |
.title() | Returns a titlecased version of the string where words start with an uppercase character and the remaining characters are lowercase |
.swapcase() | Returns a copy of the string with uppercase characters converted to lowercase and vice versa |
.strip() | Returns a copy of the string with the leading and trailing whitespace characters removed |
For the full list, see Python3 docs
Open the Class1Ex2TextProcessing repl. Let's play with some strings!
Please fill out the feedback form to let me know how I can improve the class!