Skip to content
← Back to Community
Python Basics tutorial; Session 1
Profile icon
Alice688

Python Basics


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.

Python-Programming-Edureka

print("Variables, and escape characters.")


Print() function
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
Input:

print("I love python.")

Output:

I love python.

Quotation marks
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.

Escape characters
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.

411-4117600_man-silhouette-running-escaping-person-escaping-png

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.
Input:

print("Here is a \nsentence on \nmany lines.")

Output:

Here is a sentence on many lines.

Variables


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:
Input:

print(name)

Output:

Coder

Operaters


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).

arithmetic-operators

Next, are boolean operators or comparison operators. This operator gives us an True or False output, a.k.a. a boolean type.

Greater Than

This basically asks the computer is this number greater than that one?
Input:

7 > 10

Output:

False

And seven is not greater than ten so it is False.

Less Than

Basically the same as greater than, except it checks wether a number is less than another number.
Input:

7 < 10

Output:

True

Equal to

This is checking wether something is equal to another thing.
Input:

3 == 4

Output:

False

Greater than or equal to and Less than or equal too

This is checking wether something is less/greater than or equal to something.
Input:

4 >= 5 8 <=8

Output:

True True

Not equal

This is checking if something is not equal to something
Input:

4 != 5

Output:

True

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.

And

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.
Example Input:

cookie_lovers and cupcake_lovers

This would be checking if Maria's friend is a cookie lover and cupcake lover.

Or

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.
Example Input:

cookie_lover or cupcake_lover

Not

The not operator would check wether Maria's friend is not a 'something' lover.
Example Input:

not sugerCookie_lover

End


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!")

Voters
Profile icon
Raffbpk
Profile icon
DarkThemed
Profile icon
revanthReddy8
Profile icon
ChristianP4
Profile icon
BaptisteTrimail
Profile icon
devika-UwU
Profile icon
PasinduDilshan1
Profile icon
SemereGT
Profile icon
MajdZaher
Profile icon
ArmandoMoreno3
Comments
hotnewtop
Profile icon
Leroy01010

nice tutorial!!

Profile icon
Alice688

@Leroy01010 thank you! :)

Profile icon
EpicGamer007

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!

Profile icon
Alice688

@AbhayBhat Thanks for the advice!

Profile icon
EpicGamer007
Profile icon
gibbsfreenergy

Nice Job ! You're tutorials are really in depth unlike so many other tutorials! GOOD JOB :)

Profile icon
Alice688

@JosephSanthosh Thanks! :)

Profile icon
gibbsfreenergy

Thank you too @Alice688

Profile icon
JASONLAMPLEY

I really like how each session allows me to really learn the basics more in-depth than other tutorials, which just do a quick skimming of the topics in one go.

Profile icon
NamishaKundar

Thank you so much for uploading this tutorial.

Profile icon
SketchingKiddo

Tysm!!!

Profile icon
AishwaryaGowri

i luved it !!! when will the next part come ???

Profile icon
Alice688

@AishwaryaGowri Either today or tomorrow. :)

Profile icon
ARZTV

Very good explanation....

Profile icon
Alice688

@ARZTV Thanks!😁