Beginners Python Tutorial!
Today I will be teaching you
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
- Multi-line printing
- User Input
- Calling Functions
- Basic Operators
- Basic Math Using Operators in Variables
- Multiplying lists
- Basic Math Using Operators in Variables
- Top 5 Best modules to import
So this is really basic. This is the first thing that I learned in
print('') and it will print it to the console. Example:
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('').
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:
input('ex') (Change ex to what you want.) To have a user
input lets the user type and have a response. (Also, you could use
ex = input to name one. [Replace ex] )
Challenge: Make a simple quiz game using
if == '':, and
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 == "":.
For functions, you can use
def. You can put what you want to happen underneath. This might be confusing. Example:
For this all you have to do is call the function name. so mine was
sample() so i have to type in
You don't only need to put a
def is valid and you put the name of the function with closed parenthesis then anything would work. That is just my example.
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:
You can make a list in python with the following syntax:
You can call these lists in any way you want, you can use them to list
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:
Adding words to the console using +
You can use a variable and make it have this syntax:
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.
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:
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.
Top 5 Best Modules to Import
#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.
I hoped that you like my beginner's python tutorial! If you like it please upvote.