Learn to Code via Tutorials on Repl.it!

← Back to all posts
PYTHON TUTORIAL
h
CoolCoderSJ (508)

IMPORTANT LINKS

Comparison -

FeaureInteractive OnlineNon-Int OnlinePDFJupyter
Readable ContentYesYesYesYes
Input your own codeYesNoNoYes (Your code will not be validated)
Run code snippets used in the tutorialNoNoNoYes
Open source codeYesYesYesYes

These links are powered by SJURL , my personal URL Shortener. If these links do not seem to be working, click here and make sure it says Up. If not, ping me below and I'll try to figure out why my site isn't up.

Yay my first post that came onto the 'hot' section of Repl Talk!
omg yay this is beyond expectations, 130 upvotes! Can we get to 140?

Please make sure you are signed into repl.it or else it gives an error

The Easy Way to Learn Python

With this easy to use Python tutorial, you can learn python the easy way

This Python tutorial covers -

  • IDE Comparison (Level0)
  • Your first hello world! (Level1, Print)
  • String vs. Int vs. Float (Level2)
  • Variables (Level3)
  • Conditionals, with if, elif, and else (Level4)
  • User Inputs (Level5)
  • Lists (Level6)
  • Functions (Level7)
  • 2D Lists (Level 8)
  • Loops (Level 9 & 10)
  • Dictionaries (Level 11)
  • Common Modules (Level 12)

Coming Up

I plan to add the following topics later on

Also Supports -

  • ACCOUNTS
    • These accounts are secure, and only you can access your password. Only you can delete your account, and only you can login with it.

      EDIT: I investigated a bit with the account system, and if u don't have a repl.it account/aren't signed in when using this, then ur account may be deleted if ur browser cookies/cache are cleared.

    • Accounts help save your progress so you don't have to redo hours of tutorial again.
  • Different colors to differentiate tutorial and code.
    • In this tutorial, all text isn't white; And if you get deeper inside, you'll learn how to color your text too!
  • Opportunities for you to try out the code you're learning!
    • Throughout the tutorial, you will get Opportunities to type some code, and have it verified by the PythonTutorBot.

Contributing

While I cannot allow anyone to directly edit my tutorial, you can contribute by making a pull request on the GitHub Repo. (Find it here)

Updates

LISTS GOT ADDED!

Functions are here!

Welcome, 2D Lists!

Loops just got added!

Dictionaries are here

The manual level picker now also shows what each level has, instead of just the number.

Common Modules

Bonus lesson, level0, ide comparison, added

Tell me if you have more you would like to see!
Try it out here
Btw I made this whole thing in 3 days

Note: This whole tutorial was built on my favorite IDE, repl.it

Update:
A while back, I finally set up my own URL shortener with tracking statistics and changed the link to my shortened one, and the results were amazing! The link got 14 views in an hour alone! thanks for your support everyone!

Link Clicks so far - 592 👀
EDIT: I obviously have a lot more clicks, but i'm not going to be editing this as frequently.

Comments
hotnewtop
CoolCoderSJ (508)

Reply to this thread if you want to be notified for new updates.

CoolCoderSJ (508)

@Leroy01010 okie
I plan to add at least another level by today or tomorrow

CoolCoderSJ (508)

@Leroy01010 Lists have been added! Check out level 6 for lists.

CoolCoderSJ (508)

@Leroy01010 I do be cranking out levels....
Functions have been added! (level 7)

CoolCoderSJ (508)

@Leroy01010 i feel like im on fire...
2d lists are here! (level 8)

CoolCoderSJ (508)

@supcoolak who.... are u.....? or did u mean that u just want to be pinged?

supcoolak (5)

@CoolCoderSJ Yeah, I wanted to be pinged.

CoolCoderSJ (508)

@supcoolak @Leroy01010 Bonus Lesson
IDE Comparison
Level 0
Added

CoolCoderSJ (508)

@supcoolak @Leroy01010
by the way, the PDF version is here!
(I also added these cause a lot of people wanted it but didn't have repl.it accounts)

View non interactive online here
View Downloadable PDF here

supcoolak (5)

@CoolCoderSJ This is so cool! (Totally didn't send this to a friend struggling to start learning Python). I wanted to say something about Atom, you can run code in Atom if you install the script package.

CoolCoderSJ (508)

@supcoolak wait really? thanks! (for both points)

CoolCoderSJ (508)

@supcoolak @Leroy01010 .ipynb version made, (hosted on Google Colab)
Find it here
This adds support for running code snippets throughout the tutorial and seeing live results

supcoolak (5)

@CoolCoderSJ Hey! Came here to say thank you! My friend (the one I recommended this to) and I are now making a game using pygame because of you!

CoolCoderSJ (508)

@supcoolak yay, that's great!
pygame is awesome, hope you guys have fun!

Bookie0 (6023)

Pretty nice, some tips:

The first thing to note is that there are no semicolons unlike other languages

wdym unlike other languages? not all languages have semicolens

maybe it's me, but perhaps add a space between the ] and the text? And perhaps a > or something to prompt the user?

And when I create an account, there's text but I don't get to see it as it shows for like 1 sec then disappears...

The 'Print' Statement

print doesn't have a capital P

As a note, please use single quotes, NOT double quotes.

both can be used, you should be able to accept both lol

print('Hello World')

Hello World! has an exclamation mark!

this should work, it gives the same output as what you wrote

'hullo' . Please use single quotes. Define it below

again, you don't need single quotes lol you can use double quotes.

Anyways, the rest is pretty fine! :)

CoolCoderSJ (508)

@Bookie0 hmm
thanks for ur feedback
1) I do agree, I think I should add a >
2) Yeah lol sorry I hate js ill change that
3) Yeah hmm I changed that later on, I must have forgotten to accept both in the earlier levels
4) I didn't know that, ill add an exclamation mark
5) U have a space between print and (

I don't think python accepts spaces

Thanks for ur feedback!

CoolCoderSJ (508)

@Bookie0 again, thanks for the feedback, i did change a couple of things, especially the double quotes and signup message timeout.

Btw it was supposed to tell u this after signing up
"Great! Your username is "+username+" and your password is "+password+" Don't worry, only you can access these passwords and usernames, and all data is encrypted. You're going to be redirected to the main page now, Login with your new credentials to get started."

Bookie0 (6023)

@CoolCoderSJ

ok
ok
ok
ok
uhhhhhhhhh
python does accept spaces lol if you didn't know that...

you can also put a lot of space:

np! :D

CoolCoderSJ (508)

@Bookie0 whoa cool I didn’t know that....

CoolCoderSJ (508)

@Bookie0 all right i did have to break yesterday, but as of now, it accepts spaces between print and (.

Bookie0 (6023)

@CoolCoderSJ

this normal? pretty bright lol

CoolCoderSJ (508)

@Bookie0 whoa uh u must have some external script running

This is what I see

and this is after I disabled all of my extensions

Bookie0 (6023)

@CoolCoderSJ yea I have some Chrome Flags..

Due to application errors, for new lines, type a | right after the first line, and pretend all space after that is a new line.

seriously?

what's wrong with this?

and what about this?

also you should add colors for the errors, and also specify what went wrong. You should also add more stuff! :)

CoolCoderSJ (508)

@Bookie0 yeah i really need to fix this, didn't think it was that broken

for the first one:
I think ur doing it fine, and for now u can use the manual level picker since inputs only come at the end.. i need to go through my code and accept spaces everywhere

for the second one: Again same thing:
I think ur doing it fine, and for now u can use the manual level picker since inputs only come at the end.. i need to go through my code and accept spaces everywhere

Also I ask you to put the | because I don't know how to accept multi line inputs in the console

Bookie0 (6023)

@CoolCoderSJ yez yez I do know I'm doing it fine, I'm just highlighting that ur "bot" can't see that it is correct and you should prolly correct it! ;0

Also I ask you to put the | because I don't know how to accept multi line inputs in the console

¯\_(ツ)_/¯

CoolCoderSJ (508)

@Bookie0 all right i went through my code, and I'm pretty sure that it accepts any number of spaces now (hopefully)
I do plan to add functions, lists, dictionaries, and 2d lists in the future, any suggestions for more?

Bookie0 (6023)

@CoolCoderSJ imports? eg random, time, etc.
maybe useful pieces of code (slowprint, clear screen, ANSI escape codes for colors and bold/italic)

CoolCoderSJ (508)

@Bookie0 ohk ill prob add a popular modules and their commands section

CoolCoderSJ (508)

@Bookie0 yay! I found a way to accept multi line input, so now u can hit enter and type normally for the if statement

elipie (364)

@CoolCoderSJ make lexer instead of something else...

elipie (364)

@CoolCoderSJ well.. python is the most misused(and the source of spam on replit) and really slow. You want something compiled

CoolCoderSJ (508)

@elipie wait let me get this right, u hate python because ppl spam python repls? wut a twisted logic
U don't need compiling, Pythons more lightweight
wdym by misused

elipie (364)

@CoolCoderSJ hmm, i see you have been on repl as long as me... hmm Have u been active on repl latley? lots of spamming lol

Yes u do ned compile... fast af boii

while python is:
[insert turtle with python head here]

CoolCoderSJ (508)

@elipie I am active, i did see the spam, but u cant base judgement of a language on that.
Compiling can be fast, but its really heavy, and python has tons more than just turtle.
Ever heard of web.py, flask, web2py, etc?
Reddit used to run on web.py, and Netflix and Lyft runs on flask

elipie (364)

@CoolCoderSJ exactly, python has became so big that its kinda boring, once you know all of it. And, you can easily get lost(a bad thing) once you are in the language. Thats why I am suggesting a different language

CoolCoderSJ (508)

@elipie i...don’t think it’s boring..and there’s tons of documentation..
What language would u suggest..?

programmeruser (571)

@CoolCoderSJ there's a reason people use compiled languages, it's because they're fast.
And python suffers from serious performance problems making it a slow language (see https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/python.html).
Node.js is much faster than Python and still manages to be simple.

CoolCoderSJ (508)

@programmeruser ok true, compiled can be fast, but I disagree with the fact that node js is simpler than python.

First there's the fact that there's .then() , .catch(), async functions, and it can be confusing to use those/know where to put them. I can type a line of code in python that takes 5 lines in node.js.

Second, there's the fact that python can be used for many things, like coding AI.
Yeah, Python is the #1 language to use for coding AI.

Third, python has mutatable and non mutatable (list vs tuple) while js doesnt

Fourth, python has a lot more inbuilt modules, while js doesn't have that many. that means more of npm, whereas pip3 isn't needed that often.

Btw I'm saying all these things from experience, because I have used both node and python.

programmeruser (571)

@CoolCoderSJ

I can type a line of code in python that takes 5 lines in node.js.

I suspect that's because Python uses synchronous approaches which seem to be more "simple" for beginners.

Second, there's the fact that python can be used for many things, like coding AI.

Did you know that AI and most scientific libraries are not written in Python, but in C++? If they were written in Python then they would be slow to the point of unusable.

Third, python has mutatable and non mutatable (list vs tuple) while js doesnt

Can't you just use immutable.js? And how many times have you actually used those?

Fourth, python has a lot more inbuilt modules

Node has a decent amount of built-in modules.

CoolCoderSJ (508)

@programmeruser

I suspect that's because Python uses synchronous approaches which seem to be more "simple" for beginners.

Is that really an issue if it does the same thing in an easier way?

Did you know that AI and most scientific libraries are not written in Python, but in C++? If they were written in Python then they would be slow to the point of unusable.

From a really simple bing search -

Python

Python: Python is viewed as in any case in the rundown of all Artificial Intelligence (AI) development programming languages because of the simplicity.
techindiatoday.com

Python. Python is considered to be in the first place in the list of all AI development languages due to the simplicity. The syntaxes belonging to python are very simple and can be easily learnt.
geeksforgeeks.org

First two things that come up...

Can't you just use immutable.js? And how many times have you actually used those?

While mutatable is much better to work with, immutable is preferred for faster run and shorter projects.

Node has a decent amount of built-in modules.

Its kind of annoying how I have to manually install packages in replit for node whereas with python i can type
import ... to automatically install

Additionally,

"
At this moment, there are more than 66,000 Python vacancies on Indeed and more than 40,000 JavaScript jobs.
"
Python has 22,000 more jobs available right now than js

programmeruser (571)

@CoolCoderSJ repl.it automatically installs Node.js packages.
The synchronous nature of Python is detrimental to its performance.
I forgot to mention this above, but you can create immutable objects with Object.freeze and clone objects with Object.assign.

CoolCoderSJ (508)

@programmeruser

repl.it automatically installs Node.js packages.

Ive tried with numerous repls, and it hasn't worked for me..sooo

I forgot to mention this above, but you can create immutable objects with Object.freeze

Again, node is so complicated. object.freeze? imutable objects in python are defined so simply..
imutable_var = ( "thing", "thing2", etc.)

Also you dropped 2 of my arguments, that hurts your case pretty badly.......

programmeruser (571)

@CoolCoderSJ if it hasn't worked for you, file a bug report at https://repl.it/bugs. It has nothing to do with the language itself.
How is a call to Object.freeze so complicated? The syntax for tuples is just syntactic sugar.

CoolCoderSJ (508)

@programmeruser
syntactic sugar??

let me also say something,

node is mainly built on objects, like

const that_thing {a buncha values so tat u have to use that_thing as an object}

Also u dropped 2 of my arguments (again) which still hurts your case....

CoolCoderSJ (508)

lol @Bookie0 be missing the debate
wouldnt be surprised if @programmeruser is ignoring....
:O
prob just got stuff to do

CoolCoderSJ (508)

@programmeruser nothings wrong with them, but
1) Objects arent always needed
2) They can be kinda hard to learn

programmeruser (571)

@CoolCoderSJ what do you mean they're hard to learn?
And you aren't required in use objects in js.

CoolCoderSJ (508)

@Bookie0 oh yes im so sorry i will move this to a new thread

CoolCoderSJ (508)

@Bookie0

imports? eg random, time, etc.

Im done with everything I planned, anything else?

Dov4k (0)

HOW THE HELL DID YOU DO THIS!?!?!?!?!? I NEED ANSWERS PLS!!!!

CoolCoderSJ (508)

@Dov4k lmao thanks, it took me a while, basically just made it in my free time.

Im working on an Web Dev tutorial atm...

CoolCoderSJ (508)

@MrDQuinn @danparaskev i see you all want to edit the tutorial...
While i cant allow direct editing, you can create a pull request on the Github Repo

(Just try editing the file normally, and it will ask you if u want to propose your change)

jimmytranscript (3)

Need some help with Level 7!
I keep getting an error message on line 3 when trying to call my function.
my_func() isn't working for some reason.
Let me know what I'm doing wrong please

CoolCoderSJ (508)

@jimmytranscript hmmm
what are you entering?
are u calling it at the end?
did u put at least 3 when it asked you for num of lines?

alanchen12 (28)

Just a note -
For the IDE's part (the pdf), it says atom does not have a terminal. However, there are packages that allow you to have a terminal. Also, the IDE part does not have VSCode >:(
@CoolCoderSJ
Also you should add a cancel account creation option

CoolCoderSJ (508)

@alanchen12 1) All right, I will add that later on
2) Sorry if this offends you but VSCode is overrated. I downloaded it a week ago, and it’s exactly what repl.it is just offline, and without cool features like hosting, db, etc.
3) I will add that

deucemuch (0)

I can't seem to get passed level 7 question about defining a function.
Not sure what I'm doing wrong.

CoolCoderSJ (508)

@deucemuch uh oh...
what are you entering?

CoolCoderSJ (508)

@deucemuch also note: At any point if you need to manually move levels, you can rerun the repl and choose option 4.

deucemuch (0)

@CoolCoderSJ
def my_func():
(i then receive lines of error messages)

CoolCoderSJ (508)

@deucemuch uhhh
so if i remember this correctly, it asks for the number of lines your func is going to be, since it only listens for that long. Put at least 3 there...
then do

def my_func():
    #your stuff here, after typing four spaces...... and     
    #this should be the num (of lines you entered before) - 2
my_func()

remember to call it at the end...

CoolCoderSJ (508)

@deucemuch it seems to be working for me if I put

def my_func():
    print("Stuff")
my_func()
deucemuch (0)

@CoolCoderSJ yep that was it I didn't put in the number of lines.
Preciate the help & the amazingly intricate tutorial!!

botfivehundred (1)

@CoolCoderSJ Do you know how to restart a program in python?
Like if you do:
Thingy = input("Do you want to restart? ")
if thingy == 'yes' or 'Yes:
Your answer here
I tried using return, but it doesn't work :(

CoolCoderSJ (508)

@bot502 return is only usually the end of a function. Return would be like

def wow():
    return "hi"

d = wow()

#d is "hi"

To restart a repl use

import sys
import os
os.execv(sys.executable, ['python'] + sys.argv)
CoolCoderSJ (508)

@bot502 hey also another tip is use .lower()
so

thingy = input("Do you want to restart? ")
if thingy.lower() == 'yes':
    #Func here

or .upper()

thingy = input("Do you want to restart? ")
if thingy.upper() == 'YES':
    #Func here
botfivehundred (1)

@CoolCoderSJ Oh and how do you do that thing.
Like make the script gray.
Like make a code in the comments.

botfivehundred (1)

@CoolCoderSJ And I'm making a direct print project/code thingy.
I'm not using def

CoolCoderSJ (508)

@bot502 gotchu
if u want to add code, type 3 of these --> ``` , then right in front of it type the language, then on lines under it type your code, and end with ```

Example -

```python
Code here
```

ObiVibKenobi (170)

I just got you to 90 :)

botfivehundred (1)

U wrote userinput wrong

botfivehundred (1)

And I cant get past that level...
Could you show me how? @CoolCoderSJ

CoolCoderSJ (508)

@bot502 that was intentional, in coding, usr can also be used for user.

In fact, Linux (and i think mac too) make user root folders as usr

CoolCoderSJ (508)

@bot502 yeah sure! so u put any variable you want, and make it equal to input("Your question here")

EDit:
Its not working for me, let me review my code :(

EDIT2 :
You must keep the variable as usrinput
(Silly me I didn't read the prompt correctly)

angelinalau (0)

May I ask how to do the num 5+5 one?

CoolCoderSJ (508)

@angelinalau yeah sure! so its a conditional with the variable, num. num is equal to 5+5 in integer value, but we want python to return an action if 5+5 is 10. Since the variable is predefined, use

if num 

then use 2 equal signs, because that means you are checking a value, (single means u are setting one)

if num ==

We want to know if it equals 10

if num == 10:

use a Colon to define next steps.
Now click enter, and type 4 spaces (recommended to use tab but I cant use tab In the console) We have to tab or 4 spaces because the code that is indented is inside the if, all code not indented into the if statement is run no matter what.

if num == 10:
    #action here

the action is

print("ok")

Did that help?

MonicAaaaAAaaA (0)

i can't understand anything

koschgm0 (0)

I got stuck on the Conditionals! Very interesting tutorial. Great info for us rookies!! thanks.

CoolCoderSJ (508)

@koschgm0 yay thanks!
np!

Pls upvote if u like it!

When u said u got stuck on the Conditionals, what do u mean, cause it also may have been cause of my code...

koschgm0 (0)

@CoolCoderSJ
I couldn't get the configuration to make 5+5 =10 and the console say ok! spent about 4 hours on it!!!!

CoolCoderSJ (508)

@koschgm0 ah sorry about that.....

so you were to use the variable, num (I think I put num...)
instead of 5+5, and its double equal signs

beginner10coder (12)

my check list:
IDE Comparison: yes
print hello world!: yes
string vs. int vs. float: yes
variables: yes
conditionals: yes
user inputs: yes
lists: yes
functions: yes
2d list: no
loops: yes
dictionary's: no
common modules: no

CoolCoderSJ (508)

@beginner10coder you’ve done a lot already!
How is the tutorial?
Anything more I could add?

beginner10coder (12)

add what ever you know from python @CoolCoderSJ and your tutorial was great!

Lancerianojas (0)

Hi. I appreciate your efforts however me being a beginner just know about basic commands such as if, elif and python's normal working so could you please suggest me how can I become good at python. My goal is to make a simple game and basically to explore the working of more commands. kindly guide me if possible.

CoolCoderSJ (508)

@Lancerianojas hi,
That’s great! If you are a beginner, you can complete the above tutorial, which will help you learn more. As for the game, I would recommend a console game, as graphics are a bit advanced.

EDIT:
@Lancerianojas if u did want to do graphics, I would suggest Pygame Zero, (pgzero). That's where I started for my first graphic game too. (Click here to view its docs, and click here to play it.)

CoolCoderSJ (508)

Hey everyone! I have as of now finished 13 levels, thoroughly explaining a lot of topics, and I'm done with everything I wanted to do, so if you have any suggestions, feel free to tell me!

CoolCoderSJ (508)

@programmeruser i know they arent required, but
1) I feel like most of JS is built around objects,
2) Theyre not that easy to learn for beginners

JBloves27 (1727)

Pretty cool! Nice tutorial!

CoolCoderSJ (508)

@JBYT27 thanks!

Not tryin to be a stereotypical repl talk user, but pls upvote if u liked it

elipie (364)

also, it would be way better to use double quotes, it is better practice. And you should only use single quotes for single characters.

CoolCoderSJ (508)

@elipie i agree, im pretty sure ive fixed all my code to accept both double and single quotes, if u find a place where it doesn't let u, just let me know ;)

elipie (364)

nononono dont learn python

ik it is required to get a job now but no >:(

go learn some low level language pls

Eiske (0)

Hi, I have a question about Python, what is the best version of Python with the best activity and the best community?

CoolCoderSJ (508)

@Eiske I would recommend really any version 3.0 and higher, but there’s more support (I think) for 3.6 and higher

CoolCoderSJ (508)

@pepelaugh it asks u for dupl auth? it shouldn't.. I must have put the wrong link, so sorry, could u please try now?

badst (640)

@CoolCoderSJ the website works now, the code, no. Indentation error at line 242

CoolCoderSJ (508)

@pepelaugh oh oops.. i must have moved it while editing the readme cause I did thoroughly test it

could u pls try now?