Sup ARMY, it’s time to talk about Python.

Don’t worry Hobi, this one isn’t an actual snake, you’re safe 💜
Shall we start with the history of Python a lil?
It was originally created in 1991. Python 2.0 was released in 2000 and had a 20 year life, officially discontinued THIS YEAR. It’s successor, cleverly named Python 3, was released in 2008.
The focus of Python is to be very easily readable by humans. It’s a high level programming language because of this.

High level == humans can read it
Low level == computers can read it
Python is, in my humble opinion, probably one of the best languages to learn as a beginner because of how readable it is.

Every language tutorial starts with “Hello, world!” - making the language print out an easy lil statement to greet the world (hi Jin)
With Python... it’s literally one line

print(“Hello, world!”)

Everything in quotes will be presented when the code is run.
I accidentally pressed tweet all instead of add tweet, I’m smart

Don’t be fooled by how easy Python is to start working with though, it’s a very powerful language thanks to its object-oriented nature
This means a whole program can pull on several separate pieces of code, sometimes called libraries, and put them together to do things

But what if we want it to generate a number and print a member of BTS? Let’s look at that.
This is where it can get complicated, because there’s a few ways to do this. I’m going to do it with lists and a variable for the generated number.

I also have no idea if this is going to work because I’m not on the computer that has Python set up. Oops. I’ll test it later.
We’ll be RIGHT back once I actually write this example, gimme a sec
AAAAAND let’s get it

Here’s how I would probably do a random number generation calling a member of the group (or even the whole group since I used the fan chant)
The first part of it is creating an Array. Arrays are basically lists where each number has a numerical value, starting at 0 and ending at the end of the list. This one is 0 to 7 because there’s 8 entries

Don’t ask me why arrays start at 0 because I can’t remember 😂
The next bit is saying “hey, I want a random number! Pick a number 0 to 7!”
This is pseudorandom number generation (because computers can’t really be random at all - there’s always something causing the specific value picked)
After that, we’re telling the computer “hey, I’d like that random number from that list I gave you, can you tell me what’s there?”
As well as asking the computer “dude, what was that random number?” - this is so we can check it called the right entry in the list
Sanity checking your code is important! Any time we start getting complicated, little checks like this can show you if and where something is breaking. If it’s REALLY breaking the computer will just pout and point at where what it doesn’t like is, but it won’t tell you what
I’ll be back once my shift is over in 10 hours to check this code and maybe bring you all a lil challenge based on what I’ve talked about (which isn’t much because I’m bad at general teaching, specific questions are easier to answer!) for you guys to try
Resources if you want to play around in the meantime:

http://www.learnpython.org 

I was gonna include codecademy as well but they’re still on Python 2 and we don’t need deprecated syntax thank u
You can follow @ArmyCompsci.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: