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"
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.
Functions
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:
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.
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!
"print" Statements
As tradition suggests, we'll start with a simple hello world program.
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.Variables and Conditionals
Variables can store numbers, strings, or anything you want to. Here's an example:
Variables can also make it so you don't have to type the same number over and over again:
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:
Oh, I forgot to mention one more thing.
elif
is just something that adds on to an if statement andelse
is just saying that when something happens, it will listen to anything except the commands from the other parts of the if statement before.Functions
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:
This will print out:
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.
why lol the merrier the better @EpicGamer007