Hi Queermos! I’m Intern Chloe, I’m a software engineer at a large tech company, and I want to teach you things about programming computers! Programming is one of my top three favorite activities, after eating pasta and responding to Autostraddle tech support requests. Hopefully you might want to program computers too, because there’s a ton of job growth in I.T., and while there are some pretty kick ass queer women programmers, tech is still overwhelmingly dominated by men. Also lots of girls seem to think my ability to program computers is a good reason to send me OKCupid messages, so.
Let’s talk about python. I picked python for our gentle programming introduction because when you squint really hard it allllllmost looks like regular English. There are dozens of programming languages that have different strengths and weaknesses, but once you know how to program in one it’s way easier to learn more. Python is easy to learn, but also super practical and is mostly what I use in my job.
There’s a tradition among programmers every time you learn a new language to have your first program be “Hello World,” which just prints out “Hello World.” That seems a little straight for us, so we’re gonna do “Hello Queer World” instead.
First, we need a text editor to write computer code in. I’m going to be using Sublime Text 2, which you can download for free and works on Mac, Windows and Linux. Once you’ve downloaded and installed, follow these steps:
- Open a new window
- In the menu, go to “View” > “Syntax” and select “Python.” This makes the code pretty colors, basically.
- Also in the menu, go to “Tools” > “Build System” and select “Python.” This tells the computer to read what we write as Python code.
- Then, in your window, type: print “Hello Queer World!”
It should look something like this:
The last thing you have to do in order to run your program is save it. On a Mac you can type command+”s”, or you can click “File > Save.” We’re finally ready to roll. Next, go to “Tools > Build” (or command+”b”) to actually run your code!
Does it print out something like this?
Hello Queer World! [Finished in 0.0s]
Let’s break this down a little bit. print is a special statement in python that allows us to write out information from the computer program when we run it. “Hello Queer World!” is a string. In programming, data can have many different types; a string is anything between quotation marks. Now, try to change your program to print out “Hello <your name>” instead.
Another common data type is an int, short for integer, which is pretty much what you might expect it to be, and we can do all sorts of normal math-type things with ints too. For example, all of these statements are valid:
- print 4
- print 4 + 5
- print -10 / 2
What happens if you instead type print “4 + 5?” Python just reads “4 + 5” as a string because it is in quotation marks, and so it doesn’t try to do math on it. Your window probably looks something like this:
Next we are going to talk about variables. Variables are a way of storing information that we want to use later on. For example, we could have a variable called my_name that stores a string for us. Then we can write something that looks like this:
my_name = “Chloe”
print “Hello” + my_name
And if you build this, it should print Hello <your name>. Variables can store any type of information; for example, maybe I also wanted to print out my age:
Disaster! This is our very first error message, which is telling us that we can’t add strings and ints together because they are different types. Error messages are really useful when you mess up — they try to give you information to fix the problem.
We can fix this by casting my_age to be a string instead — that is, changing it’s type for the purpose of printing it out:
Great job so far! You are learning so many things! Try making the above print statement more complicated and adding more facts about yourself using variables.
Ok ready for the last new big thing? The next major concept is called a function, which is a piece of code that you can reuse over and over again. For example, say I wanted to print out the name and age of anyone, not just myself. I could individually write out each print statement:
This is going to get really cumbersome because what if more Ellens come out? What then, will we just keep copy pasting code?! We need a function to end the madness.
def print_info(name, age):
Functions always start with a special keyword, def, which means that we are defining a function. Then comes the name of the function, print_info, and then the information that the function takes in — name and age. Below the function definition, we write the code that will be called every time the function is called.
def print_info(name, age):
print name + “is” str(age)
There are three important things to note about every function:
- The name: print_info
- The arguments: name (a string), age (an int)
- What it does when you call it: prints out name and age
A couple of things to notice about this code: mainly, you can think of print_info as a shortcut for the code inside the definition. Instead of having to type out the messy print statement over and over, you can just type print_info with the information you want it to contain. Also, notice how name and age look all orange and strange in the function definition. They are still variables, but a special kind of variable called function parameters that you send into the function when you call it, and then the function can use them like regular variables. Lastly, the line under the function definition is indented several spaces. Python actually cares about proper indentation, which means every time you end a line with a “:” you indent the next line 2 spaces. Sublime is awesome and will take care of this for you magically, but it is still worth knowing.
It’s super ok if this is confusing! Functions are scary and strange at we’re gonna do another example and then you can practice on your own.
Now, try on your own to write a function that takes in two ints as inputs and prints out the sum of them (I know it’s silly; bear with me). Ready go! Scroll below the next cat to find the answer:
Ok did you do it? Here’s my solution:
Cool! Great job! You know so many things about programming now! Though this is possibly the only “learn to program” guide on the internet using cat interstitials, you might want to learn more after this (I hope you do!). I highly recommend code.org for an excellent introduction. If you want to keep going, Coursera has a great selection of free online courses. What do you think? Was it confusing? Do you want to learn more? Were there enough cats? Tell me all your feelings about programming!
This has been the eighty-fourth installment of Queer Your Tech with Fun, Autostraddle’s nerdy tech column. Not everything we cover is queer per se, but we talk about customizing this awesome technology you’ve got. Having it our way, expressing our appy selves just like we do with our identities. Here we can talk about anything from app recommendations to choosing a wireless printer to web sites you have to favorite to any other fun shit we can do with technology.
Feature image via Shutterstock.
Header by Rory Midhani
HI CHLOE!!! This is awesome! Also, perfect amount of cats :)
Whew, glad you think there were the right amount of cats.
This has reminded me to finally finish my computer science project and study for my final. I wish my professor brought up cat pictures in his lectures. I would have so much more motivation then.
I’m pretty shocked at how much I remember from taking python in college, although I suspect I’d remember even more had my professor used cats as a learning tool!
Cool another use for Sublime Text!
I had to install Python though. Anyway, great amount of cats and thank you for actually clearing my doubts between programming and design. I am actually going to start programming for a living. I made the account (although I read Autostraddle every day) just to comment on your post. Thank you!
This makes me so happy, that’s great you’ve decided to be a programmer!!
Thanks for this!! I’ve been fooling around on code academy during my break and while I could do some of Python this is a really good complement to some of the things I’ve been struggling with.
Glad you liked it! If you let me know some of the things that are confusing I might be able to help out and/or cover more topics in the future.
Really glad to see this article here, Python is an awesome language for getting started with programming.
There’s a great textbook called How to Think Like a Computer Scientist that teaches programming using python. It’s free online as an interactive book (you can type code and see output right in the browser!); you can find it here:
http://interactivepython.org/runestone/static/thinkcspy/index.html
Awesome to see this on AS!
This article is great. And it’s such good timing as well, because I’ve literally just started trying to learn how to programme (do programming?)
So, thank you for sharing, this is very helpful :)!
OMG! Intern Chloe Forever!
<3
I’m just really distracted by the kitten pictures
This is a wonderful little guide and would have been way better than how I was taught when I first started programming in high school. Somehow, despite that awful Java class sophomore year, I still wanted to do compsci in college. Of course, I didn’t graduate with that degree but alas, I still have a fondness for programming. Just not pointers. Never ever ever pointers.
Also there totes can never be enough cats but any amount of cats is superior to no cats.
Maybe this article will inspire me to start programming again xD You should write more.
Javascript for Cats
Dang, I would know SO MUCH about programming if kittens were a regular part of the curriculum.
Do you have advice on how to learn assembly? I have to learn it for my internship this Summer…and I didn’t even know it existed a month ago. I’ve tried to find tutorials online but I guess there is not a lot of demand?
Ah, what do you have to use assembly for? I took a course in it. Not sure of any good online resources.. It’s pretty dry no matter how you learn it.
I think I have a PDF textbook if you want to take a look.
Basically the computers at my work are outdated, and my boss told me I need to use assembly to program a PIC18F2525 microchip to run a sequence of LED’s.
That would be very cool to see the PDF book, thanks for offering!
my email is believethehypatia at gmail.com
I’ve been going through this online tutorial, too:
http://www.tutorialspoint.com/assembly_programming/
Found a tutorial for programming your microcontroller series here: http://www.pic18f.com/
If you haven’t found it already, here’s what wikipedia has to say: http://en.wikipedia.org/wiki/PIC_microcontroller#PIC18_high_end_core_devices_.2816_bit.29
Thanks for the links, I will definitely try that out!
This is super cute and is inspiring me to learn Python! Delightfully straightforward-looking.
I also want to give a shoutout to Codecademy – that’s the site I’ve been using to gradually improve my skills; I’ve gone from zero to HTML+CSS+Javascript. It’s really good at reinforcing what you’ve already learned and combining concepts!
The cats totally validate how I felt while reading the article.
Needs more cats*
This was a wonderful little introduction to Python! Yay for queer programming! And I also second the idea of CodeAcademy; as some in the comments have pointed out, it’s a lovely little site that can help bare bones beginners or refresh long time programmers.
Yes, thanks everyone for mentioning codeacademy I don’t know how I forgot it!
“This is going to get really cumbersome because what if more Ellens come out? What then, will we just keep copy pasting code?!”
Chloe you are perfect and I love you. Also I wanted to comment on the quality of cats in this post. I feel like this many cats in one post COULD have gotten overwhelming. But they were really good cats, so I approve. ALSO I actually understood what you were trying to say w/r/t coding and it made me strangely nostalgic for that one coding class I took in high school.
Really great intro to Python! It is on my increasingly growing list of languages to learn – sitting somewhere between ruby and swift I think. Completely forgot how easy it is to understand though!
Pretty sure if there were more tutorials with kittens I would have picked it up sooner…
My top three things after reading this article:
Intern Chloe
Intern Chloe
Intern Chloe
…. wait those were always my top three favorite things.
I don’t understand how going through all of those extra steps is better than just typing “Ellen Degeneres is 56”. If you wanted to make a whole list you would still have to type all of the data plus the commands. I feel like I am missing something!
It’s just because it’s a small example that it doesn’t save typing. The advantage comes when your data (the names and ages) comes out of e.g. a spreadsheet, and then you could use the print_info function for each person to print them all out in a list.
In fact, you would make a loop, and tell python (effectively) “do print_info for everyone on the spreadsheet” instead of “do print_info for the first person, then do print_info for the second person, then…”
You’re not missing anything! It’s true it doesn’t save you any typing at all in this case–it was just an example to try to demonstrate what a function does. The other reply has it exactly right-it starts to save you time when you have way more people or a more complicated function. I plan on elaborating on this in a future post-thanks for the feedback!
Yessssssss thank you, Chloe! I’m entering the big scary world of Python for SPSS and this is the perfect non-threatening intro I needed.
Thank you for such a great information you providedread about Cryptocurrency
Great intro! I also highly recommend GitHub’s text editor, Atom. Though sublime is free, if you don’t get a registered version they always prompt you to buy it… Atom is completely free and super customizable. It has all of the basics (syntax highlighting, autocomplete) and tons of other packages.
Thanks so much!!! I work with GIS and I’ve been plodding through various python tutorials so I can make GIS work better and faster. This was very concise and way more fun than using examples of imaginary tables of imaginary things I don’t really care about. (For GIS users, ESRI has a very kind, free tutorial: http://training.esri.com/gateway/index.cfm?fa=catalog.webcoursedetail&courseid=2520“>a very kind, free tutorial.
Thank you so much for this. Look:
Okay did that work? We shall see. :3
Thank you so much for this. Look:
DID IT WORK THIS TIME??
Okay thank christ it worked. Also: thank you to Ali for her HTML comment tutorial. All my image fails are belong to me.
I’m so excited about this new world I’m discovering!
:D :D :D :D :D
from here i get latest versionnotepad++ plugin manager
i think we should do programming in this
thanks for sharing these information are informative article with all of us.
thanks for sharing these information are informative article with all of us. Kinemaster Lite
Hello, Dear thank you for your support and help it was helpful for me, to keep posting such informative stuff with us. Also, check our captionme.net for daily social life help.
Hey, Action lover, do you want to play the most popular action game Nulls Brawl in your mobile, then try this out with unlimited money?
One of the top shooting games is Pure Sniper Mod Apk. It offers stunning super HD 3D visuals and an engaging universe. The background of the game is presented in a way that piques your attention since it is spectacular in many parts of the planet.
May You Like Too: Pure Sniper MOD APK
Despite the fact that there are many shooting conflicts within the gaming industry, competitive game enthusiasts select capturing action.
May You Like Too: Pure Sniper MOD APK
Do you know YouTube is a most loved video streaming platform? which you can make it more amazing with YouTube ReVanced app.