🐍Python basics tutorial🐍
What is Python Anyways?
Python is a programming language made for readability and is great for large projects such as :
Web development with flask
Chatbots with text to speech and vice versa
Comments can be used to add pointers and tell people looking at your code what it might do. They can also be used to comment out code that you don't want. We do this by putting a # in front of the line to be commented out like this:
Sadly there is no milti-line comments in python so we can either put a # on each or we can write a milti-line comment that isn't assigned to
print() is used to log data to the console similar to
print() and concatenate them, we will learn about this later.
Strings can be put inside of single quotes like this:
'Hello World!' or in double quotes like this:
"Hello World!", we will use "". Multi-line comments can be used by doing triple quotes like this:
The output when printed will be:
This is great but how do we use this? first create a new repl in the language : Python with the blue and yellow snake then title it: Python Tutorial. on the first line write
print("Hello World!") and press run at the top. Congratulations, you have written your first line of code! Now comment out that line because we will not need it later.
Variables can be set equal to Booleans, Strings, arrays, tuples, and integer like so:
In Python Tutuorial add a variable called name and set it equal to a string with the value of your name.
next print that variable by using
print() like this
You can also change the value of a variable later on in your code. So now if we re-assign the name variable like this:
name = "A different name than before" and then print it again using
print(name). You will notice that 2 different names are logged to the console, this is because in between both prints we changed the value of the variable we wanted to print.
integers are just numbers like 1, 2, or 3. And if we set a variable equal to an integer and put it inside type() which will return the type of variable that it is it should return int or integer like this
if you are setting a variable don't set it with "" set it without any just a number.
Don't do this:
integer = "12"
integer = 12
str() and int()
First let's talk about concatenation and what that means. It means that we can add variables and strings inside one
print(). first add a print and set it to print the string "My name is " and then after you comment out the second name from the previous exercise add your name to it like this:
print("My name is "+name)
This will output:
My name is Liam
However if we try to print our variable called integer which is set to 12 in a string we will get an error like this:
This will raise an error but luckily for us there is a fix to this by using str() and turning 12 into "12" and int() could be useful for if then statements and taking user input, we'll learn this later. So now if we add str to our
print() like this:
An error will not occur here because we used
Booleans can have a value of either
False and are mostly just usefull for loops and if, then statements. and when a variable with the value of a boolean is printed it will display True or False and when setting a variable to True or False we capitalize it and we don't put quotes around it.
Tuples can be used to store multiple values in a single variable and it'll look like this:
tuple = ("string number one","string number two")
Now if you print the variable it will output:
('string number one','string number two')
But if you print only first value like this
print(tuple). It will output:
string number one
Note: when requesting a specific value from a tuple always start counting from zero.
To Be Continued
I would downvote this if I could - there are wayyyyyyyyyyyyy tooooooo many Python tutorials for a language that isn't all that great.