Learn to Code via Tutorials on Repl.it!

← Back to all posts
Beginners Python Tutorial!
SamiOsman

Beginners Python Tutorial!

Hello guys!

Today I will be teaching you Python basics.

To those of you who say there are too many python tutorials just for cycles, I wholeheartedly agree. I am not just doing this for cycles. I want to help people. This is purposely for beginners and it is supposed to only cover the basics.

Table of contents

  • Printing
    • Writing
      • Multi-line printing
  • User Input
    • If...Else
  • Functions
    • Calling Functions
  • Variables
  • Lists
  • Basic Operators
    • Basic Math Using Operators in Variables
      • Multiplying lists
  • Top 5 Best modules to import
  • End

Printing


So this is really basic. This is the first thing that I learned in Python. Use print('') and it will print it to the console. Example:


Writing


This is basically the same as printing but it writes the text letter by letter. you need this code for it to work:

Thank you to @KierstenKuk for this on their repl called Detective's Case! Also just check out their profile too. They are an amazing coder! (Check out their Profile.) By the way, from this point on I won't use write(''). I will still use print('').


Multi-line printing


This is pretty simple. All you have to do is add six quotations or ( '''ex'''). Write in the middle of them. This is if you want to add the key enter into the printing. Or if you want to add an apostrophe. (and other things) If not you would get this error: SyntaxError: EOL while scanning string literal Example:

I also think that this is worth mentioning here: if you also want a multi-line string using a different way you could use \n. What this means is that it is a line break. Example:


User input

Use input('ex') (Change ex to what you want.) To have a user input. Using input lets the user type and have a response. (Also, you could use ex = input to name one. [Replace ex] )


If...Else

Challenge: Make a simple quiz game using input(''),if == '':, and else:

In order to make the input actually work you need to add if '':. If you wanted someone to answer a question then you use if == "yes": and if == "no":. You can use else: to determine if the user has made an input that is not defined by the if == "":.
Example:


Functions


For functions, you can use def. You can put what you want to happen underneath. This might be confusing. Example:


Calling functions


For this all you have to do is call the function name. so mine was sample() so i have to type in sample(). Example:

Output:

You don't only need to put a print. As long as the thing inside the def is valid and you put the name of the function with closed parenthesis then anything would work. That is just my example.


Variables


So in order to define a variable you have to do sample = 4 that is a variable. You can also use quotations to define a variable as a word. Like this: sample = 'example' you can change the number and the example. If I used:

Output:


Lists


You can make a list in python with the following syntax:

Output:

You can call these lists in any way you want, you can use them to list

Basic Operators

Challenge: make a calculator using basic operators. (Using input might be a good idea).

Basic Math Using Operators in Variables

You can make a variable using math. If you want to use addition use +. If you want to do subtraction use -. If you want to use multiplication use *. If you want to do division use /. Use two starts/multiplication signs to do to power. Example:

Output:


Adding words to the console using +

You can use a variable and make it have this syntax:

Output:

What this does is it adds words together using the + sign. It adds these words together: 'This' + 'space' +'is'+'space'+'an'+ 'example.' and it prints it to the console.

Output:


Multiplying Strings to Make Multiple of the Same Sentence


This is pretty easy. Make a variable called whatever you want and then add a multiplication sign (*) to whatever you want to multiply. Example:

Output:

Multiplying using lists

You can multiply with strings following this syntax:

With this what you are doing is 123x2. The output might make it easier to understand.


Output:


Top 5 Best Modules to Import


#1 Art. This is for ASCII art/text. Me and my friend made a repl using art. Check it out! It is a Text2Ascii art converter! Here is the link. for more info and syntax about the art module visit here.

#2 Wikipedia. I do not even know for this one. You can literally just import the whole Wikipedia. For more information and its syntax visit here.

#3 Time. My favourite use for time is time.sleep(3). You can change the time inside the parenthesis. That stops the next line of code for how many seconds you put inside the parenthesis. For more info about time and syntax visit here.

#4 OS. My favorite use for os is os.system('clear'). What this does is clears everything in the console. For more information about os and its syntax visit here.

#5 Turtle. Turtle is a module that lets users draw. This is one of my favourite modules. For more information and syntax visit here.


End


I hoped that you like my beginner's python tutorial! If you like it please upvote.

Voters
CoreyThomson
cuber1515
SamiOsman