Python Basics tutorial; Session 1
What is Python?
Python is a general-purpose computer language.
Created by Guido van Rossum, and released in 1991.
And it particularly emphasizes code readability.
print("Variables, and escape characters.")
The print() function is probably the most used lines of code.
It is used when we want to output a string. A string is a collection of characters, or text.
This function takes in a few different parameters, but we'll talk about that later.
Parameters are pieces of input (information) you give the function to do something.
This function is very helpful in debugging code as well.
You write the print statement by putting what you want to be printed in the parentheses
print("I love python.")
I love python.
In a print statement you have to have quotation marks. You also have to make sure there the same type, ex: ' ' - same type " " - same type
The same goes for parentheses.
Now what if we needed to use quotation marks....let's say on a quote. And you just put quotation marks in quotation marks. Well, this would happen:
print(""Flowers are beautiful" said Flora") File "<stdin>", line 1 print(""Flowers are beautiful" said Flora.") ^ SyntaxError: invalid syntax
A Syntax Error is when you have a problem with your syntax, Syntax Error is basically a language error
So what's the solution? The solution is escape characters. Basically help you escape the problem.
The escape character you would use in this case is a backlash. So your code would look like this:
print("\"Flowers are beautiful\" said Flora.")
And your output would be:
"Flowers are beautiful" said Flora.
But, what if you wanted to use multiple lines? There's a escape character for that, too. All you have to do is put '\n' every time you want it to go to a new line.
print("Here is a \nsentence on \nmany lines.")
Here is a sentence on many lines.
Variables are basically labeled boxes in which you store strings and integers in. (You should know what integers are.)
And when you put them in print() functions your telling the computer to print whats in that box.
You write a print statement by giving your string/integer a name then use the = sign. Here's what I mean:
name = 'Coder'
name = label 'Coder' = string/integer
So then you would put your variable (box) in your print statement:
There are many different types of operators, but we'll just focus on three: arithmetic, boolean, and logical operators. A operator is a symbol or function that tells the computer to use a certain operation.
Here is a chart of arithmetic operators, which are basically math operators:
Remember to use order of operations (PEMDAS).
Next, are boolean operators or comparison operators. This operator gives us an True or False output, a.k.a. a boolean type.
This basically asks the computer is this number greater than that one?
7 > 10
And seven is not greater than ten so it is False.
Basically the same as greater than, except it checks wether a number is less than another number.
7 < 10
This is checking wether something is equal to another thing.
3 == 4
Greater than or equal to and Less than or equal too
This is checking wether something is less/greater than or equal to something.
4 >= 5 8 <=8
This is checking if something is not equal to something
4 != 5
Remember, that you can use boolean operators with variables as well as numbers!
Finally, logical operators, these help us compare True or False operands. This is good, cause it makes our code smarter. There are three main logical operators:
and, or, and not.
So let's say Maria has multiple friends. And we want to pick the cupcake lovers from the cookie lovers.
The and operator helps us check for two True operands.
cookie_lovers and cupcake_lovers
This would be checking if Maria's friend is a cookie lover and cupcake lover.
So using the Maria's cookie and cupcake loving friends case again. The or operator would check if her friend was a cookie lover or a cupcake lover.
cookie_lover or cupcake_lover
The not operator would check wether Maria's friend is not a 'something' lover.
That's it for Session 1 (there will be a Session 2).
If you have any questions, advice, or corrections please comment, and I will reply.
Hope this is useful for you!
(Also check out Part 2, I have finally finished it! Here's the link: https://repl.it/talk/learn/Python-Basics-Tutorial-Part-2/55062!")
Good! In depth explanation, I like it! Just one thing to know. I think it would be better if you made one long tutorial instead of many short ones. It would be more informative and gain more support from other replers(I think). Having "sessions" or a "series" can make it seem like you are cycle farming. Thank you and great job!