Skip to content
← Back to Community
A Python Tutorial, the Basics
Profile icon
JBloves27

🐍 A very easy Python Tutorial! 🐍

#Tutorial Jam

@elipie's jam p i n g

Here is a basic tutorial for Python, for beginners!

Table of Contents:

1. The developer of python

2. Comments/Hashtags

3. Print and input statements

  • f' strings

4. If, Elif, Else statements

5. Common Modules

1. Developer of Python

It was created in the late 1980s by Guido van Rossum in the Netherlands. It was made as a successor to the ABC language, capable interfacing with the Ameoba operating system. It's name is python because when he was thinking about Python, he was also reading, 'Monty Python's Flying Circus'. Guido van Rossum thought that the langauge would need a short, unique name, so he chose Python.

For more about Guido van Rossum, click here

2. Comments/Hastags

Comments are side notes you can write in python. They can be used, as I said before:

  • sidenotes
  • instructions or steps
  • etc.

How to write comments:

#This is a comment

The output is nothing because:

  1. It is a comment and comments are invisible to the computer
  2. Comments are not printed in Python

So just to make sure, hastags are used to make comments. And remember, comments are ignored by the computer.

3. Print and Input statements

1. Print Statements

Print statements, printed as print, are statements used to print sentences or words. So for example:

print("Hello World!")

The output would be:

Hello World!

So you can see that the print statement is used to print words or sentences.

2. Input Statements

Input statements, printed as input, are statements used to 'ask'. For example:

input("What is your name?")

The output would be:

What is your name?

However, with inputs, you can write in them. You can also 'name' the input. Like this:

name = input("What is your name?")

You could respond by doing this:

What is your name? JBYT27

So pretty much, inputs are used to make a value that you can make later.

Then you could add a if statement, but lets discuss that later.

3. f strings

f strings, printed as f(before a qoutation), is used to print or input a value already used. So what I mean is, say I put an f string on a print statement. Like this:

print(f"")

The output right now, is nothing. You didn't print anything. But say you add this:

print(f"Hello {name}!")

It would work, only if the name was named. In other words, say you had a input before and you did this to it:

name = input()

Then the f string would work. Say for the input, you put in your name. Then when the print statement would print:

Hello (whatever your name was)!

Another way you could do this is with commas. This won't use an f string either. They are also simaler. So how you would print it is like this:

name = input() ... print("Hello ", name, "!")

The output would be the same as well! The commas seperate the 2 strings and they add the name inside. But JBYT27, why not a plus sign? Well, this question you would have to ask Guido van Rossum, but I guess I can answer it a bit. It's really the python syntax. The syntax was made that so when you did a plus sign, not a comma, it would give you an error.

Really, the only time you would use this is to give back your name, or to find if one value was equal to each other, which we'll learn in a sec.

4. If, Elif, Else Statements

1. If Statements

If statements, printed as if, are literally as they are called, if sentences. They see if a sentence equals or is something to an object, it creates an effect. You could think an if statement as a cause and effect. An example of a if statement is:

name = input("What is your name?") #asking for name if name == "JBYT27": print("Hello Administrator!")

The output could be:

What is your name? JBYT27 Hello Administrator!

However, say it isn't JBYT27. This is where the else, elif, try, and except statements comes in!

2. Elif Statements

Elif statements, printed as elif are pretty much if statements. It's just that the word else and if are combined. So say you wanted to add more if statements. Then you would do this:

if name == "JBYT27": print("Hello Administrator!") elif name == "Code": print("Hello Code!")

It's just adding more if statements, just adding a else to it!

3. Else Statements

Else statments, printed as else, are like if and elif statements. They are used to tell the computer that if something is not that and it's not that, go to this other result. You can use it like this (following up from the other upper code):

if name == "JBYT27": print("Hello admin!") elif name == "Squid": print("Hello Lord Squod!") else: print(f"Hello {name}!")

5. Common Modules

Common modules include:

  • os
  • time
  • math
  • sys
  • replit
  • turtle
  • tkinter
  • random
    etc.

So all these modules that I listed, i'll tell you how to use, step by step! ;) But wait, what are modules?

Modules are like packages that are pre-installed in python. You just have to fully install it, which is the module(please correct me if im wrong). So like this code:

import os ...

When you do this, you successfully import the os module! But wait, what can you do with it? The most common way people use the os module is to clear the page. By means, it clears the console(the black part) so it makes your screen clear-er. But, since there are many, many, many modules, you can also clear the screen using the replit module. The code is like this:

import replit ... replit.clear()

But one amazing thing about this importing is you can make things specific. Like say you only want to import pi and sqrt from the math package. This is the code:

from math import pi, sqrt

Let me mention that when you do this, never, ever add an and. Like from ... import ... and .... That is just horrible and stupid and... Just don't do it :)

Next is the time module

You can use the time module for:

  • time delay
  • scroll text

And yeah, that's pretty much it (i think)

Note:

All of the import syntax is the same except for the names

Next is tkinter, turtle

You can use the tkinter module for GUI's (screen playing), you can import it in a normal python, or you can do this in a new repl.

You can use the turtle for drawing, it isn't used much for web developing though.

The math and sys

The math is used for math calculations, to calculate math. The sys is used for accessing used variables. I don't really know how I could explain it to you, but for more, click here

Random

The random module is used for randomizing variables and strings. Say you wanted to randomize a list. Here would be the code:

import random ... a_list = ["JBYT27","pie","cat","dog"] ... random.choice(a_list)

The output would be a random choice from the variable/list. So it could be pie, JBYT27, cat, or dog. From the random module, there are many things you can import, but the most common are:

  • choice
  • randrange
    etc.

And that's all for modules. If you want links, click below.

And that's it!

Hooray! We made it through without sleeping!

Credits to:

  • Many coders for tutorials
  • Books and websites
  • replit
  • etc.

Links:

Web links:

ranging from a few days or hours
if you like reading

Video links:

ranging from 1-12 hours
if you don't like reading

Otherwise:

ranging from 5 hours-a few days
replit tutorial links

I hope you enjoyed this tutorial! I'll cya on the next post!

stay safe!
Voters
Profile icon
Joyoski
Profile icon
Flippybear
Profile icon
RyanKeeler
Profile icon
VAalchemist
Profile icon
svsmith
Profile icon
MossMidd
Profile icon
Sebasp1
Profile icon
AdrianaQuizhpi
Profile icon
Lexximoa
Profile icon
KaiserFranz
Comments
hotnewtop
Profile icon
[deleted]

thats nice

me who knew all of it but still is new to python

Profile icon
JBloves27

Thanks! lol @Z3FFY

Profile icon
[deleted]

@JBYT27 wow you replied within 2 minutes

Profile icon
JBloves27

xD ;) @Z3FFY

Profile icon
Coder100

coder100 likes to lurk

Profile icon
JBloves27
Profile icon
DiveshTheReal

This is a good tutorial thx for this :D

Profile icon
JBloves27

Thanks! np! @DiveshTheReal

Profile icon
DiveshTheReal
Profile icon
JBloves27
Profile icon
Bookie0

Hum ok pretty decent tutorial, some tips:

for comments, you can also have multiple line comments:

""" multiple lines yay """
  1. If and Else Statements

elif...?

  1. Common Modules
    Common modules include:
    os
    time
    math
    sys
    replit
    turtle
    tkinter
    etc.

never heard of the "etc." module lol

The most common way people use the os package is to clear the page.

how?

whateveryouwanttoputhere = input("What is your name?")

pretty long variable, not really recommended..

you can also clear the screen using the replit package

how? examples?

and the random module (randint, randrange, choice)?

and you should prolly include more examples, especially on the modules. also what about variables? for loops? while loops? lists? you're spending a bit more time on the modules than other python ueufl things tbh..

but thank for ping I guess. Maybe try adding some more things to the tutorial, but otherwise, nice start! :D

Profile icon
JBloves27

Ok, thx for the suggestion! Its my first tutorial too, so im prob gonna be bad, lol @Bookie0

Profile icon
Bookie0

@JBYT27 cool np! :D

Profile icon
JBloves27
Profile icon
Bookie0

(^β€Ώ^) @JBYT27

Profile icon
JBloves27

Elipie said I couldn't fix too much, but later on a different tutorial, i'll do what you said! :) Thanks btw! @Bookie0

Profile icon
Bookie0

@JBYT27 wdym? you can and should always try ti fix things ig :)

Profile icon
JBloves27

@Bookie0, ik, but bc it's a submission... ima make a editted v. later ;)

Profile icon
Bookie0

@JBYT27 hum well ok then, ig you could say that what you edit isn't part of the submission, but if you make another post edited, make sure to edit/add many more things, so that it's not just almost the same thing!
γ€€β—•β€Ώβ—•γ€€

Profile icon
JBloves27

got it! @Bookie0

Profile icon
Bookie0

cool! Β¬β€ΏΒ¬ @JBYT27

Profile icon
InvisibleOne
import replit import os os.system("clear") #clears the screen replit.clear() #clears the screen again

@Bookie0

Profile icon
Bookie0
Profile icon
Bookie0

@InvisibleOne but os.system('clear') can be used not only on the repl.it IDE i think

Profile icon
InvisibleOne

Yeah, it doesn't work on my other IDE's @Bookie0

Profile icon
Bookie0

@InvisibleOne ya, tis why os.system('clear') superior lol :)

Profile icon
InvisibleOne
Profile icon
JBloves27
Profile icon
CoolCoderSJ
Profile icon
JBloves27
Profile icon
[deleted]

Really helped for a beginner like me. Can’t make much with it, but it’s a great start. Thanks JBYT27!

Profile icon
JBloves27

NP! glad it helped! Yeah, im making an edited version of it, i hope you see it later! @hen0tic02

Profile icon
ItzMalakai

Thanks, it really helped since it was well explained and I'm new to coding. Let me know where to start off since youtube videos are like 4 hrs+ and they don't really explain what they do.

Profile icon
JBloves27

Oh, ok glad I helped @ItzMalakai

Profile icon
ThatOneGuy1234

How does this only have 23 votes? (24 including mine (: )

Profile icon
JBloves27

lol, thx! I hope you learned something! @ThatOneGuy1234

Profile icon
AnshumaanBajpai

Thanks for this tutorial. Will be looking forward for further tutorials. :)

Profile icon
JBloves27
Profile icon
Astro3000

This was the tutorial that inspired me to start coding.

Profile icon
JBloves27

Omg, thanks! @Astro3000

Profile icon
TheMerDragon

This is really helpful for explaining it to others! Thanks!

Profile icon
JBloves27

Thanks! Np :) @TheMerDragon

Profile icon
adamgadd99

nice

Profile icon
JBloves27
Profile icon
heavyduck

posting a comment to save this, thank you very much!!!!!!!!!!!!!!!!! :D youre a godsend

Profile icon
JBloves27

Np! Lol, thanks! Glad you like it so much! :D @heavyduck

Profile icon
ETICHUR2018

thanks dude, i am pro at python now :D

Profile icon
JBloves27

np! yay! :D @ETICHUR2018

Profile icon
JWZ6

great tutorial thanks mate

Profile icon
JBloves27

Thanks! Np! @JWZ6

Profile icon
StevenVoronko

A nice, structured and concise tutorial. I recommend changing this part though so as to avoid confusion;

The output would be a random choice from the variable/list. So it could be pie, JBYT27, cat, or dog. From the random module, there are many things you can import, but the most common are:

  • choice
  • range
    etc.

I recommend changing the range to randrange, syntax: randrange(start, stop, step), since randrange() is the module included in the 'random' library which will create a list of integers and return a random number from said list, whereas the range function, syntax: range(start, stop, step), is a built-in function that only creates a list of integers in a given range, commonly used in for loops as an Iterator

Profile icon
JBloves27

ah, ok. Thanks for the suggestion! @StevenVoronko

Profile icon
riparino

This is great!

Profile icon
JBloves27

thanks! @riparino

Profile icon
YazCar

Thanks!

Profile icon
JBloves27

np! glad i helped! @YazCar

Profile icon
cynthiawachira

#this was helpful

Profile icon
JBloves27

:D glad it was! @cynthiawachira

Profile icon
billypeterson

thats great tutorial for beginners. It's well explained. Waiting for your next tutorials. Also check"https://favtutor.com/blog-details/7-Python-Projects-For-Beginners" for python beginners project. It's also very helpful. Hope you like it.

Profile icon
JBloves27

Thanks! i'll look at the tutorial! @billypeterson

Profile icon
RealAnt101

lua is pretty similar to python, thanks for the tutorial tho!

Profile icon
JBloves27

oh, i didn't know that! thanks for letting me know! Np! @Andromida

Profile icon
heavyduck

thanks! this is really handy since im a beginner. thanks once again :D

Profile icon
JBloves27

np! glad you learned something! @heavyduck

Profile icon
pyashika

thank u very much i have also posted a simple addition program pls see it

Profile icon
JBloves27

Thanks! Glad I helped! Ok, sure! @pyashika

Profile icon
BoyAhmed

u know when i use the if statements then how comes when i use the hashtag it doesnt turn green

Profile icon
JBloves27

the green you can just ignore. it only happens usually with complexity stuff and module stuff. @BoyAhmed

Profile icon
BoyAhmed

@JBYT27 so i dont have to do the green part?

Profile icon
BoyAhmed

@BoyAhmed and thanks for replying so fast i really appreciate it
:)

Profile icon
JBloves27

Yeah. lol, np! glad you learned something! @BoyAhmed

Profile icon
LeliaByerley

Thank you, this helped a lot, I was completely lost at first but this described everything very well :D

Profile icon
JBloves27

Np! I’m glad I helped! @LeliaByerley

Profile icon
[deleted]

thank you. i appreciate this totorial.

Profile icon
JBloves27

Np! Thanks! @bowmand117

Profile icon
[deleted]

@JBYT27 ur welcome. i thought this was for javascript for a sec and tried coding with it then realized it was for python XD

Profile icon
JBloves27

XD hope u learned something! @bowmand117

Profile icon
[deleted]

@JBYT27 i did. before this, i only knew block coding on https://www.scratch.mit.edu, and even then i wasnt that good.

Profile icon
JBloves27

cool! Glad you learned somethin! Check out the other python tutorial links as well, they are much better than mine, lol @bowmand117

Profile icon
catspython

You CAN use pluses, but you can't put strings and ints together, but also you can make ints strings w/ the str() funcion by putting a int into the funcion like this, str(5[it can be any int]) this outputs this, 5, or, "5"

Profile icon
JBloves27

Oh, ok. Thx for the tip! @catspython

Profile icon
catspython

@JBYT27 Your welcome, I didn't know that you can use commas, nor that f-strings even existed!

Profile icon
JBloves27

Lol, glad I helped as well! @catspython

Profile icon
OlauPla

Ok, going to be hones haven't read it all because very simple but it looks very good! I

Profile icon
JBloves27

lol, thanks! @OlauPla

Profile icon
OlauPla
Profile icon
elipie

nice, ima judge this

Profile icon
JBloves27
Profile icon
JBloves27

1 question, could I edit this a bit? @elipie

Profile icon
elipie

@JBYT27 uh, only a bit, i already judged it :)

Profile icon
JBloves27
Profile icon
ETICHUR2018
Profile icon
JBloves27
Profile icon
ETICHUR2018

@JBloves27 idk i was just doing it

Profile icon
JBloves27