GDI Logo

Welcome to Girl Develop It

GDI Logo

We create welcoming, supportive and accessible environments for women and non-binary adults to learn software development.

Code of Conduct

We are dedicated to providing a welcoming and comfortable environment for all to learn coding.

girldevelopit.com/codeofconduct/

bit.ly/gdi-incident-report

Some Guidelines

  • We are here for you
  • Every question is important
  • Help each other
  • Participate, Experiment, Have Fun!

What Does
Girl Develop It
Teach?

Web Development

Data Science

UX Design & Research

Workforce Classes

Career-Building Events & Conferences

GDI Logo

Find All Our Classes & Events:

www.girldevelopit.com

Your Instructor

Liz Krznarich (she/her)

Technical Lead, DataCite

Many tech hats worn! Fullstack engineer, frontend engineer, technical trainer, graphic designer...

Python, Java, JS (Angular/React/Ember), DevOps (Ansible/Terraform/Puppet)

Fun fact: Degrees in Art and Library Science. First professional job involved hot dog ads.

GDI Logo

Intro to Python

Python is on fire!

Top general-purpose language in the 2022 StackOverflow developer survey

Top language in the PYPL index

Used by tech giants, including:

  • Google
  • Netflix
  • Instagram
  • Spotify

Why does everyone love Python so much?!

Course Outline

What is Python?

Why learn Python?

One way to use Python (repl.it)

Python basics (variables, functions, troubleshooting)

What is Python?

The Python language

  • An "interpreted" general purpose programming language.
    • Huh?? Runs through an interpreter application, as opposed to "compiled" languages, which are converted to machine code and run directly by a computer
  • Verbose, with an easy-to-read syntax
  • Open source
  • Can run on many systems: *nix, Windows, Mac

Python history

  • Not new! Developed in the 1980s and first released in 1991
  • ...but many of its most useful features weren't added until v2.0 in 2000
  • Current version is 3.x; 2.x deprecated in 2020

Python philosophy

From "The Zen of Python":


						Beautiful is better than ugly.
						Explicit is better than implicit.
						Simple is better than complex.
						Complex is better than complicated.
						Readability counts.
					

"Pythonic" = code that’s easy to read, follow and understand

Code example

Key difference from other languages: whitespace is significant!

Statements _must_ be indented


                    def add_numbers_between(start, end):
                        sum = 0
                        for n in range(start, end):
                            sum += n
                        return n

                    add_numbers_between(5, 10)
                    

Why Python?

Very flexible!

Python is "multi-paradigm" and supports a variety of programming approaches:

  • Procedural
  • Functional
  • Object-oriented

Many uses

  • Scripting, ex automating tedious tasks, cleaning up data
  • Backend (server-side) apps
  • Web applications, especially using frameworks like Django and Flask

Easy to learn & read

  • Code style emphasizes readability
  • Methods have human-readable names
  • Readable code = easier to maintain

Loads of built-in features

Python standard library includes everything you need for common tasks:

  • Text processing
  • Interacting with your local operating system
  • Working with files
  • Working with JSON & CSV
  • ...and so much more!

Very extensible!

Can't find what you need in the Python Standard Library? There's probably a package for that!

  • ~400,000 packages in the Python Package Index (PyPi)
  • Loads of packages for working with common APIs (Google, Github, AWS...)
  • Built-in package manager pip

Very extensible!

Popular, well-maintained frameworks available for quickly building web apps

Often used to build REST APIs, which can be connected JS frontends, but can also serve frontend via a template system

Are there any downsides?

  • Memory hog - can be slow, not good for games/graphics
  • Not for mobile apps
  • Dynamic typing = runtime errors (thorough testing needed)

Replit Walkthrough

www.replit.com

Replit setup

We'll use Replit for our coding exercises in this class.

  • Create a Replit account
  • Once you're logged in, create a new Python repl
screenshot of repl

"Hello World"!


						#print "Hello World" to the screen
						print("Hello World")
					

Inputs


						#use input() to ask users to provide input
						input("What is your name? ")
					

Data types


						#this is a string
						print(type("Hello World"))

						#this is a integer (no decimals)
						print(type(3))

						#this is a float (decimal places)
						print(type(3.1))
					

Variables


				#assign a name to a literal value
				my_var = "foo"

				#assign a name to an input value
				user_name = input("What is your name? ")
			
  • Lowercase
  • Separate words with underscores
  • Make names meaningful, ex first_name rather than fn

Functions


			#you can create functions to do a specific task

			def add(x, y):
 			  answer = x + y
 			  print(answer)

			add(2, 3)
			

Your turn!

Create a function called "mult" that multiplies two numbers and prints the answer to the screen.

Use your new function to find the answer to 12345 * 6789 = ?

Boolean Data Type


						#boolean data types are True/False
						a = True
						print(type(a))

						b = False
						print(type(b))
					

Boolean Expressions


						#boolean expressions evaluate to True or False
						a = 1
						b = 2


						print(a > b) #is a greater than b?
						print(a < b) #is a less than b?
						print(a == b) #is a equal to b?
						print(a != b) #is a not equal to b?
					

If, Else statements


						#you can have your code make choices with if, else
						a = 1
						b = 2

						if a == b: #if the statement evaluates to True
						  print("a is equal to b")
						else: #if the statement evaluates to False
						  print("a is not equal to b")

					

If, Else statements cont.


						#if, else statements with strings
						day = "Friday"

						if day == "Friday":
						  print("Happy Friday!")
						else:
						  print("Have a good day!")

					

Putting it all together!


						def hello(day):
						  print("Happy "+ day)
						  if day == "Friday":
						    print("It's almost the weekend!")
						  else:
						    print("Have a good day!")

						hello("Saturday")
						hello("Friday")

					

Lists



						#list can hold multiple elements of different types
						my_list = ["hello", 1, 3.5]

						#lists start at 0
						my_list[0]

						#how many elements are in my list?
						print(len(my_list))

					

Using "elif" (else+if) to add another expression


						def hello(day):
						  print("Happy "+ day)
						  if day == "Friday":
						    print("It's almost the weekend!")
						  elif day in ["Saturday", "Sunday"]:
						    print("Woohoo! It's the weekend!")
						  else:
						    print("Have a good day!")

						hello("Saturday")
						hello("Friday")
						hello("Tuesday")

					

Try to break your code!


						def hello(day):
						  print("Happy "+ day)
						  if day == "Friday":
						    print("It's almost the weekend!")
						  elif day in ["Saturday", "Sunday"]:
						    print("Woohoo! It's the weekend!")
						  else:
						    print("Have a good day!")

						hello("saturday")

					 

Making the code more robust


						def hello(day):
							print("Happy "+day+"!")
							#change day into all lowercase
							day = day.lower()
							if day == "friday":
								print("It's almost the weekend!")
							elif day in ["saturday", "sunday"]:
								print("Woohoo! It's the weekend!")
							else:
								print("Have a good day")

						hello("saturday")
						hello("FRIDAY")
					 

Want to learn more?

Join us for our Python 1 class series starting next week!

  • Meets weekly on Wed 4-6pm EDT, Aug 24-Sep 28
  • Covers Python basics - data types/structures, expressions, functions, loops
  • Preview the class materials

New GDI Courses

www.girldevelopit.com/events

GDI Logo

Thank You!