seo

Intro to Python [Part 2]

Want to use Python, but don’t know where to begin? Britney and Pumpkin are here in their second episode as co-hosts with more great tips on how to get started! 

Photo of the whiteboard outlining the basics of Python.
Click on the whiteboard image above to open a larger version in a new tab!

Video Transcription

Hi, Moz fans. Welcome to another edition of Whiteboard Friday. I’m your host Britney Muller. I was previously Moz’s Senior SEO Scientist, and now I am freelance consulting and building some data science programs on the side.

This is my very special co-host, Pumpkin. You might remember her from the first Python episode. She’s gotten quite a bit bigger. Quarantine was really good to her. She’s very healthy and very sweet. I love her so, so much. This is my best buddy right here. 

So we have been hard at work preparing Python 2.0 for you all, and we’re so excited to show you what we put together. So let’s just get started. 

Why Python?

All right. So we kind of went over this in the first Python video, but just to recap.

On the first video I got to hold her in one hand. It’s a bit harder now. That’s actually why I’m wearing this. I thought I could maybe BabyBjörn you. Oh, she’s fine. 

Okay, So just to recap, why Python? It’s talked about so much in the SEO community. Why is this sort of the program that most people prefer? 

Simple syntax

So there’s very simple syntax. It’s sort of more common sense than other programming languages. It also uses a ton of white space. So you’re going to see tabs and sort of white spaces instead of curly brackets like some other common programming languages.

It’s concise

Did you have something to say? It’s very concise. Often there are fewer lines of code to do one thing than there might be in another language, which is very, very nice. 

It’s versatile

It’s also very versatile. It works on many different platforms, and it can work in a different variety of ways. As far as procedural, you’ve probably heard of object-oriented and functional programming.

It kind of covers the gamut in that way, which is really great. You think so too? Pumpkin says she thinks so too, and it’s awesome. 

Getting started

So let’s get started. So whether you’re on a Mac or a Windows, you can open up a terminal and Python should come with your Mac OS system.

There’s 2.7 kind of natively installed, and we can just use that. Or go ahead and just open a Colab notebook. So this is a Google property we’ll link to down below. You can create a new code cell. All I want you to do is simply type in print parentheses. 

Sorry, what are these? Help me. Parentheses and then quotes, sorry. We’re quarantined. You know? It’s just been us two. 

So print (“Hello World”) and then Shift + Enter. Congratulations, you’ve just run Python.

So we’re off to the races. You’re all Python experts basically. 

Python fundamentals

Now, let’s kind of cover some of the fundamentals. These are really important especially just to be aware of as you kind of continue exploring — oh, is she on my mic, sorry — as you continue exploring Python.

Basic syntax

So we’re first just going to go over some of the basic syntax, and there’s obviously a lot more than just this, but some of the common things. 

1. Variables

Variables are super, super important in Python. So this is where you just assign values to words or whatever variables you’re working with. This is sort of a silly tax price example here, where we assign a numerical value to tax and we do the same for price.

Pumpkin is showing you. She’s very excited about this example. You simply run this within Python, and you will get your price plus the tax that we have stated here. So it’s kind of a cool application just to quickly get a feel of how variables work and how when you’re dealing with numerical variables, you can do a variety of calculations.

So that’s a super powerful thing within Python and really fun to play around with.

2. Comments

Second big, big important syntax is comments. So if you have something to say, like Pumpkin here, you have to put kind of a hash and then write your comment after that.

Commonly people will use these to explain the code that’s after the comment. So you can kind of explain what you were trying to do there. It’s also very useful if you want to comment out code. So I use this all the time when I’m kind of fumbling and trying to do different things within a Colab notebook and it’s not working.

I will just comment out different things and try different ways, and oftentimes that helps me kind of find solutions quickly. 

3. Data types

The next and perhaps the most powerful thing, especially if you want to start using Python for data analysis, so let’s say you want to start pulling in Google Search Console data or Google Analytics, so, so important to be aware of the different data types.

So if you’re pulling in text, like keywords from Search Console, it should be picked up in Python as string (str). Sometimes this gets screwed up when you import data. So it’s really important to have the proper data types assigned to your different types of data so that you can perform correct calculations.

So for numeric values, you have integer or just int, float, and complex. If your numbers aren’t in these data types, you won’t be able to run different calculations on them. So again, just to be aware that these exist and really the gist of it is you basically just want your data to be reflective of the proper Python data types.

So sequence is listed as those three — list, tuple, and range. Mapping is really common if you’re using dictionary type things within different programs. Then, of course, our most common, Boolean, which is true or false, is just bool. 

So is Pumpkin a big, happy girl? True. She’s actually a boy. That’s a long story. But you can call her whatever. She’s having so much fun, and she’s so happy to be here. 

4. If…else

Lastly, the if…else statement. So there’s a number of different statements that you can use.

But arguably one of the more common is if else. So just a really silly example, let’s say you have Website A ranking 13 for a keyword and Website B ranking 28. You can say print (“A”) if A < B else print ("B"). So this is just a really silly, quick example to kind of show you how you can use this.

But once you get into that, you get into elif and loops, and it gets really, really fun and exciting. 

Conclusion

So hopefully, you start to play around with some of these and stay tuned for when we apply this to Google Search Console data. So thank you so much for kind of checking out this Python 2.0 basics.

My co-host is hiding behind my back right now, but she is really grateful that you all came to check out the second video of Python. So thank you, guys, so much and Pump and I will see you guys soon. Bye.

Video transcription by Speechpad.com

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button