A Beginner's Guide To Python 🐍
A Beginner’s Guide To Python
Hey there! 👋
I’m @imightbenutella, and I’m quite experienced at Python3 myself - and I want to share that! Python is the easiest computer language you can learn, whether you’re doing it for fun or for business (python is more commonly used in data managing - more on that later). The best part? Experience doesn’t matter
So what is Python?
No, I’m not talking about the snake. (hisssss 🐍)
Python is a computer language, and to save time, I’m going to skip the history lesson - partly because I don’t remember much about the history of Python myself…
Python is really helpful if you’re new to programming, and it’s code is easy to read and understand. In this article, I’m going to cover a few basics:
- Print statements & strings
- Formatting strings, booleans and integers.
So let’s start :)
No ‘var’s here, just buckets! 👀🧺
Here’s how to make a variable:
variable = 8
So, above, we create the variable,
variable (I am very creative). Inside
variable, we stored the number/integer 8. Say, I want to do something with it. Maybe… add 2 in it? Let’s create a variable for 2 - and let’s make it longer. Obviously, I can’t go and type
variable 2 = 2. That’ll cause an error. Instead, we type:
variable = 8 variable_2 = 2 add_both = variable + variable_2
BOOM! We added variables! Umm.. just one problem. How do we see the result?
Print statements & strings
Strings of banan- sorry, text 🍌
Print statements make a variable, string, integer (number) or boolean appear in your console. A string contains text, and is wrapped in “” or ‘’. Like so - “Bananas are yellow” or ‘Bananas are yellow’. And here’s how to implement print - with our previous code.
And that prints 8 in the console. If you want to add two variables, here’s how to do it:
print(variable + variable_2)
Here’s a string variable:
string= “bananas are yellow” print(string)
And here’s how to add strings:
print(“bananas are “ + “yellow”)
Aliens can’t read the code 👽
If you create something for aliens, you need something to tell humans what a certain bit of code does. Comments are the way to do it. Let’s type up a comment:
# this is a comment! #this is also a comment!
Python is easy.... True or False? ❓
Booleans are conditions - whether True or False. For example,
boolean = True print(boolean)
Formatting strings, booleans and integers.
Imagine a bunch of cows, sheep and goats in one place… 🐐
Maybe you want to use strings and integers in one place. There is a way to do that. There are three ways to do this -
int(). Here’s how to use each.
string = “bananas are yellow ” integer = 8 boolean = False bool_str = str(boolean) int_str = str(integer) print(string + bool_str + int_str) str_bool = bool(string) int_bool = bool(integer) print(boolean + str_bool + int_bool) str_int = int(string) bool_int = int(boolean) print(integer + stri_int + bool_int)
This might be hard to understand… But remember, it’s all just buckets!
Have fun, and happy coding! 😃
Nice! One suggestion though, "bucket" might not be the right term since it implies a variable can store multiple values, but other than that this was a neat tutorial :)