Python Basics!!!

Quote of awesomeness: “It’s harder to read code than to write it.” ~ Joel Spolsky

Let’s learn some basics!

Here are some simple datatypes:

  • Integers (whole number)
    • 1, 2, 3, 4, 5, 6….

 

  • Floats (decimals)
    • 1.1, 1.2, 1.3, 1.4, 1.5…..

 

  • String (anything in “quotation marks”)
    • “hello”, “my”, “awesome”, “readers!”

 

  • Boolean (I know, sounds kinda funny right)
    • these datatypes are values at two constant objects
    • a boolean is either True or False (yes, with a capital T and a capital F)

 

Want to do something cool? Yeah, me too. Okay, once you open up your terminal, type in and press enter. The next that should have happened is that your terminal should have showed this:

>>>

Did you know??!!: #when a hashtag is put in python, this is known as a comment and it doesn’t affect the code

Did you know that we can keep datatypes stored into variables? It works like this. When you write a variable a word or letter, for example, then followed by this is a equal sign you can assign a variable. Let’s try it out on your terminal! Try doing something similar to the following:

>>> x = “helllloooooo thereeee!!!”

When you pressed enter, you must have not seen anything happen but just another >>>. But, it’s okay, here’s the thing. The string I just put with the variable is now stored. So when I put my variable alone this is what happens:

>>> x

Press enter and theeeeen!!

>>> helllloooooo thereeee!!!

TADA! WASN’T THAT SUPER COOL?!?! And, that’s just the very basics of what can be reached with python. 

You can even do some math with python. The arithmetics might be slightly different but I’m sure you will get the hang of it soon!:

  • Multiply (it’s the asterisks sign)
  • Division (it’s the slash)
  • Addition (it’s the plus sign)
    • +
  • Subtraction (it’s the minus sign)
  • Exponentiation (it’s two asterisks)
    • **
  • Modulus (it’s the percentage sign) 
    • %
    • this divides a number with another number and inputs the remainder

Here’s an example of each of these signs and their outputs. You can also test this out on the python which we opened up earlier on the terminal.


multiplication, *

>>> 2 * 9

When we put the equation above, our output would be

>>> 18


 

division, /

>>> 256 / 2

The output would be:

>>> 128


 

addition, +

>>> 1000 + 1000

The output would be

>>> 2000


 

subtraction, –

>>> 500 – 200

The output would be:

>>> 300


exponentiation, **

>>> 4 ** 2

The output would be:

>>> 16


 

modulus, %

>>> 2 % 5

Would get the output of:

>>> 1


 

Go on. Try experimenting at your terminal!

!important! : Unlike other programming types, python is very picky with whitespace. Meaning the indentations! Sometimes an error on expected or unexpected indentations may rise here and there but it’s nothing a few backspaces or the tab button can’t handle.

We’ve gotten down with some of the very basics that can be done with programming. With what you’ve learned here so far try exploring and trying this out! 

Yours truly,

L.O.A.S.H

Advertisements