Learn to Code via Tutorials on Repl.it!

← Back to all posts
The Basics of Python 2.7 (Part 1)
TheGameCreator (12)

Hey there! In this tutorial I will teach you the basics of Python 2.7. Python is a great starter language to learn as a first time coder, and Python is really useful for many things.

So, without further ado, LET'S GET STARTED!

"print" Statements

As tradition suggests, we'll start with a simple hello world program.

print "Hello, world!"

print basically prints statements into the console using single or double quotes. raw_input is a lot like that too, except you can type words or letters after the statement. You can also use it in variables, which we're going to talk about soon.

aa = raw_input("Type any number: ")

Variables and Conditionals

Variables can store numbers, strings, or anything you want to. Here's an example:

population = 1287435

Variables can also make it so you don't have to type the same number over and over again:

print "The population is " + population
print population + "people is way too much in a small city!"

As for conditionals, or if statements, if something happens in the program, they will get called and do something. Here is an example of an if statement:

bb = raw_input("Type 54: ")

if bb == "54":
print "u said 54"
elif bb == "55":
print "55? no no no"
print "wut"

Oh, I forgot to mention one more thing. elif is just something that adds on to an if statement and else is just saying that when something happens, it will listen to anything except the commands from the other parts of the if statement before.


For a quick ending to this tutorial, we will cover functions. Functions store code that can be reused again and again, much like variables, but variable can only hold data types, such as numbers, and functions can hold code. Here's a function:

def cows_fart(cows):
  print "There are " + cows + " cows farting."


This will print out:

There are 5 cows farting.

Thanks for reading!

Well, you made it to the end of the article! Now you can create basic programs with Python 2.7, and this article will eventually have a part 2. Well, goodbye!

NOTE: Unfortunately, Python 2.7 is outdated on many browsers. I will make a Python 3 tutorial soon.

CodeLongAndPros (1564)

Ok this is a bad tutorial. Nothing against you, nice writing, but btw Python 2.7 is EOL which means it’s no longer supported and lacks TONS of features like with, generators, walrus operator, fstrings…
It’s better to just learn python3

mwilki7 (1129)

I wouldn't say the contents of the tutorial are bad due to the language being outdated, rather put a disclaimer that there is a more up-to-date version available.

CodeLongAndPros (1564)

@mwilki7 Yes, when python3 has literally been around for a decade.

mwilki7 (1129)

But is it a bad python 2.7 tutorial?

CodeLongAndPros (1564)

@mwilki7 No, I said the writing was fine, the topic was not. The only reason you would touch python 2 code is if you’re porting.

mwilki7 (1129)

How is the topic not okay if it's about using python 2.7? What it is currently used for is irrelevant. If that were the case, the programming language jam was a huge waste of time (and I don't think it was).

firefish (930)

Wow! You are post number 55555


But python 2.7 had support dropped in january so... nyeh

Bookie0 (5587)

My tutorial:

Your tutorial:

hummmmm lol

Good start, but like the other comments say Python 2.7 is outdated, you should make it on python 3. Also, yours is very brief, maybe add some more details? and input? lists, comments, concatenation, data types, etc? lol

EpicGamer007 (1464)

@Bookie0 , we dont need more basic python tutorialssssss

Bookie0 (5587)

why lol the merrier the better @EpicGamer007

EpicGamer007 (1464)

@Bookie0 , "the merrer the better"? I think u mean the more the merrier but... i mean, ask @CodeLongAndPros he can explain it better than i can why there should not be as any python basics tutorials..

Bookie0 (5587)

lol dude I was being kinda sarcastic. Ofc I dont want loadssss fo python basic tutorials, that would be too much spam, but some in a while dont do bad. So I guess that tutorial is ok, as long as the person edits it, adds more, and generally makes it more detailed. Like it'd be better if tutorials had more length @EpicGamer007

CodeLongAndPros (1564)

@EpicGamer007 There should be competition ofc but 100? Excessive.

Bookie0 (5587)

yea especially if those 100 are all low-effort/spam :/ @CodeLongAndPros