The Basics of Python 2.7 (Part 1)
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!
As tradition suggests, we'll start with a simple hello world program.
print "Hello, world!"
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" else: 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." cows_fart("5")
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.
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