Learn to Code via Tutorials on Repl.it!

← Back to all posts
🐍Python basics tutorial🐍
LiamBerube (2)

What is Python Anyways?

Python is a programming language made for readability and is great for large projects such as :
Web development with flask
Chatbots with text to speech and vice versa
Data analysis

Comments

Comments can be used to add pointers and tell people looking at your code what it might do. They can also be used to comment out code that you don't want. We do this by putting a # in front of the line to be commented out like this:

# This line is commented out
# print("This line won't print because it's commented out!")

Sadly there is no milti-line comments in python so we can either put a # on each or we can write a milti-line comment that isn't assigned to

print()

print() is used to log data to the console similar to console.log() in JavaScript. You can put variables and strings inside of print() and concatenate them, we will learn about this later.

Strings

Strings can be put inside of single quotes like this: 'Hello World!' or in double quotes like this: "Hello World!", we will use "". Multi-line comments can be used by doing triple quotes like this:

"""
Some text
More text
etc
"""

The output when printed will be:
Some text
More text
etc
This is great but how do we use this? first create a new repl in the language : Python with the blue and yellow snake then title it: Python Tutorial. on the first line write print("Hello World!") and press run at the top. Congratulations, you have written your first line of code! Now comment out that line because we will not need it later.

Variables

Variables can be set equal to Booleans, Strings, arrays, tuples, and integer like so:

boolean_1 = True
boolean_2 = False
string = "Hello World!"
big_string = """
Lorem ipsum unem
etc
"""
array = [value1,value2,value3]
mytupel = (value1,value2,value3)
integer = 1

In Python Tutuorial add a variable called name and set it equal to a string with the value of your name.
next print that variable by using print() like this print(name).
You can also change the value of a variable later on in your code. So now if we re-assign the name variable like this: name = "A different name than before" and then print it again using print(name). You will notice that 2 different names are logged to the console, this is because in between both prints we changed the value of the variable we wanted to print.

Integers

integers are just numbers like 1, 2, or 3. And if we set a variable equal to an integer and put it inside type() which will return the type of variable that it is it should return int or integer like this

integer = 12
print(type(integer))

!Common Mistake!
if you are setting a variable don't set it with "" set it without any just a number.
Don't do this:
integer = "12"
Do this:
integer = 12

str() and int()

First let's talk about concatenation and what that means. It means that we can add variables and strings inside one print(). first add a print and set it to print the string "My name is " and then after you comment out the second name from the previous exercise add your name to it like this:
print("My name is "+name)
This will output:
My name is Liam
However if we try to print our variable called integer which is set to 12 in a string we will get an error like this:

integer = 12
print("The variable labeled integer is set equal to"+integer)

This will raise an error but luckily for us there is a fix to this by using str() and turning 12 into "12" and int() could be useful for if then statements and taking user input, we'll learn this later. So now if we add str to our print() like this:

integer = 12
print("The variable labeled integer is set equal to"+str(integer))

An error will not occur here because we used str().

Booleans

Booleans can have a value of either True or False and are mostly just usefull for loops and if, then statements. and when a variable with the value of a boolean is printed it will display True or False and when setting a variable to True or False we capitalize it and we don't put quotes around it.

Tuples

Tuples can be used to store multiple values in a single variable and it'll look like this:
tuple = ("string number one","string number two")
Now if you print the variable it will output:
('string number one','string number two')
But if you print only first value like this print(tuple[0]). It will output:
string number one
Note: when requesting a specific value from a tuple always start counting from zero.

To Be Continued

Comments
hotnewtop
codingjlu (76)

Wait a minute............... did you just say Siri, Alexa, Google???? Nuh uh!

codingjlu (76)

I would downvote this if I could - there are wayyyyyyyyyyyyy tooooooo many Python tutorials for a language that isn't all that great.

Th3Coder (68)

@codingjlu haha... yeah, Python has weird syntax and is slow compared to languages like C and C++!

IMayBeMe (334)

@codingjlu in my opinion I feel like python is exists mostly to learn programming and isn’t really for production level programs. I guess it also is pretty useful for quick scripts due to its simple syntax

codingjlu (76)

@IMayBeMe well not really a lot of companies are using Python...

IMayBeMe (334)

@codingjlu Yeah but they usually use it more behind the scenes with data than they actually do with user interaction.