Python 101 – Learning About Loops

There are many times when you are writing code that you will need to find a way to iterate over something. Perhaps you’ll need to iterate over the letters in a string or the objects in a list. The process of iterating over something is done via a loop.

A loop is a programming construct that allows you to iterate over chunks. Those chunks could be the letters in the string or the lines of a file.

In Python, there are two types of loop constructs:

  • The for loop
  • The while loop

Besides iterating over sequences, you can use a loop to do the same thing multiple times. One example is a web server that is basically an infinite loop. A server waits, listening for a client to send it a message. When it receives the message, the loop will call a function in response.

Another example is the game loop. When you beat a game or lose a game, the game doesn’t usually exit. Instead, it will ask you if you want to play again. This is also done by wrapping the entire program in a loop.

In this chapter you will learn how to:

  • Create a for loop
  • Loop over a string
  • Loop over a dictionary
  • Extract multiple values from a tuple
  • Using enumerate with loops
  • Creating a while loop
  • Breaking out of a loop
  • Using continue
  • Loops and the else statement
  • Nesting loops

Let’s get started by looking at the for loop! Continue reading Python 101 – Learning About Loops

PyDev of the Week: Cristi Vlad

This week we welcome Cristi Vlad (@CristiVlad25) as our PyDev of the Week! Cristi teaches cybersecurity with Python on his Youtube Channel. He has also authored some books and writes on his blog. You can see his books there too.

Let’s take some time to get to know Cristi better!

Cristi Vlad

Can you tell us a little about yourself (hobbies, education, etc):

I always loved numbers. With a Master’s Degree in Civil Engineering, I decided to pass on a great job opportunity in the field upon finishing my studies and to try my shot at computer stuff.

There was something about the combination of entrepreneurship and improving my physiology that had a hard pull on me. So I began studying how to improve my physical and mental capacity, I delved into biochemistry, human anatomy and the scientific literature of sorts and I ended up writing 7 books on physical improvement.

With an innate curiosity, I always tried teaching myself computer programming but, failed miserably for a couple of times. I tried learning JAVA, as I wanted to also wear the hat of Android developer. This was between 2011 and 2015.

I thought of giving programming the last shot and if I were not to make any progress, I would quit the effort completely. Continue reading PyDev of the Week: Cristi Vlad

PyDev of the Week: Qiusheng Wu

This week we welcome Qiusheng Wu (@giswqs) as our PyDev of the Week! Qiusheng has developed several Python packages that you can check out on Github. Specifically they are geemap, lidar, whitebox and they are used for advanced geospatial analysis. Qiusheng also has a website where you can learn more about his research and interests.

Let’s take a few moments to get to know Qiusheng better!

Qiusheng Wu

Can you tell us a little about yourself (hobbies, education, etc):

My name is Qiusheng Wu. I obtained my Ph.D. degree in Geography from the University of Cincinnati in 2015. Currently, I am a tenure-track Assistant Professor of Geographic Information Science (GIS) in the Department of Geography at the University of Tennessee, Knoxville (UTK). Prior to joining UTK, I was a tenure-track Assistant Professor in the Department of Geography at Binghamton University, State University of New York (2015-2019).

My research interests include Geographic Information Science (GIS), remote sensing, and environmental modeling. More specifically, I am interested in applying geospatial big data, machine learning, and cloud computing (e.g., Google Earth Engine) to study environmental change, especially surface water and wetland inundation dynamics. I am a strong advocate of open science and reproducible research. I have developed and published various open-source packages for advanced geospatial analysis (e.g., geemap, lidar, whitebox), which are available on GitHub. I recently created a YouTube channel to share video tutorials for using the Earth Engine Python API and geemap Python package. My goal is to make geospatial technologies and GIS programming easier and more accessible. More information about my research and teaching can be found at https://wetlands.io.

In my spare time, I enjoy coding, cooking, and playing badminton. Continue reading PyDev of the Week: Qiusheng Wu

PyDev of the Week: Jan Giacomelli

This week we welcome Jan Giacomelli (@jangiacomelli) as our PyDev of the Week. Jan is an entrepreneur and blogs about Python. You can see what projects Jan contributes to over on Github.

Let’s spend a few minutes and get to know Jan better!

 Jan Giacomelli

Can you tell us a little about yourself (hobbies, education, etc):

I’ve been programming for a while. I started when I was a high school senior – I made scraper for online betting webpages. After that, I studied electrical engineering and finished my MsC degree. Since my student years I’ve been working as a software engineer.

I’ve been training alpine skiing for almost a decade. After that, I also got a ski instructor license. Therefore in the winter ski centers are the place to go. I also love windsurfing and squash. Besides sports I also like to play guitar and cook. Continue reading PyDev of the Week: Jan Giacomelli

PyDev of the Week: Samuel Hinton

This week we welcome Samuel Hinton (@samreayh) as our PyDev of the Week! Samuel has written quite a few projects in Python and given lots of talks on astronomy. If you are interested in either of those topics, then you should definitely check out his website or his Github profile.

Let’s take a few moments to get to know Samuel better!

Can you tell us a little about yourself (hobbies, education, etc):

Sure thing! I’m an astrophysicist that started off my career in robotics engineering. I’ve always been one for trying out new things and don’t mind jumping topics, so from there I went into IT, software engineering, the finance sector, physics and then decided that space science was cool enough to put a few years into it! When I’m not coding, either for work or on a fun side project, I’ll tend to jump between introverted phases of devouring fantasy novels, and the occasion extroverted phase of doing science outreach, including one fun time when I was invited to play Australia Survivor as an academic champion. That was fun. Crazy, but fun.

The goal is to one day live and work on every continent on the planet, which means one of these days I better leave my home country of Australia and go exploring! Continue reading PyDev of the Week: Samuel Hinton

Python 101: Conditional Statements

Developers have to make decisions all the time. How do you approach this problem? Do you use technology X or technology Y? Which programming language(s) can you use to solve this? Your code also sometimes needs to make a decision.

Here are some common things that code checks every day:

  • Are you authorized to do that?
  • Is that a valid email address
  • Is that value valid in that field?

These sorts of things are controlled using conditional statements. This topic is usually called control flow. In Python, you can control the flow of your program using if, elif and else statements. You can also do a crude type of control flow using exception handling, although that is usually not recommended.

Some programming languages also have switch or case statements that can be used for control flow. Python does not have those.

In this chapter you will learn about the following:

  • Comparison operators
  • Creating a simple conditional
  • Branching conditional statements
  • Nesting conditionals
  • Logical operators
  • Special operators

Let’s get started by learning about comparison operators! Continue reading Python 101: Conditional Statements

Python 101: Learning About Sets

A set data type is defined as an “unordered collection of distinct hashable objects” according to the Python 3 documentation. You can use a set for membership testing, removing duplicates from a sequence and computing mathematical operations, like intersection, union, difference, and symmetric difference.

Due to the fact that they are unordered collections, a set does not record element position or order of insertion. Because of that, they also do not support indexing, slicing or other sequence-like behaviors that you have seen with lists and tuples.

There is two types of set built-in to the Python language:

  • set – which is mutable
  • frozenset – which is immutable and hashable

This article will focus on set.

You will learn how to do the following with sets:

  • Creating a set
  • Accessing set members
  • Changing items
  • Adding items
  • Removing items
  • Deleting a set

Let’s get started by creating a set!

Continue reading Python 101: Learning About Sets

PyDev of the Week: Gaetan Delannay

This week we welcome Gaetan Delannay as our PyDev of the Week! Gaetan is the creator of Appy, a Python web framework and an entrepreneur.

Let’s spend some time getting to know Gaetan better!

Can you tell us a little about yourself (hobbies, education, etc):

It is quite unusual for me to talk about myself, but let’s give it a try. Almost 11 years ago, I started a one-man-company, called GeezTeem. 90% of my time is devoted to coding in Python, developing and maintaining about ten software products for the public and not-for-profit sectors in Belgium. Being monomaniacal, all this stuff is made with Appy, my own (GPL) framework for building web applications in Python.

Convinced by the open source philosophy, the large majority of my code is open source, published under the GPL license. Before flying with my own wings, I have spent the previous 10 years working in various companies, public entities or research centers, learning and experimenting all aspects of software engineering, as developer, tester, researcher, quality engineer or software architect, in fields as varied as 3D graphics, requirements engineering, proton therapy control software or management information systems.

The starting point was a master degree in Software Engineering from the university of Namur in Belgium. Besides coding, writing (in french), playing tennis and composing music are my favourite activities. After publishing my first album under the name Null ID, some people told me I was probably mentally affected.
Continue reading PyDev of the Week: Gaetan Delannay