What will we cover?
We will take you from knowing nothing about Python, what to install to get started, how to write your first programs, make a few interactive programs, and learn a few string methods.
Finally, if you still are hooked, guide you to our free 8 hours Python course for beginners, which is a 17 lesson course, including 17 projects and 17 video tutorials you can follow along.
Step 1: Install JuPyter Notebook and Launch your first Notebook
Anaconda install all you need and it is free. That is, it install Python, most of the libraries you need, and a simple interactive environment to develop Python code in, the JuPyter Notebook.
- Anaconda installs all and you can launch JuPyter Notebook from Anaconda Navigator (often just called Anaconda).
- JuPyter Notebook can navigate through your files and open Notebooks, where you write your code.
How to get started?
- Go to Anaconda and download the individual edition (it is free).
- It will install Python and Jupyter notebook. That is all you need to get started and it is all free.
- Launch Anaconda Navigator.
- In Anaconda launch Jupyter Notebook.
- Navigate to a place where you want to save your files.
- Create a new Python Notebook with the “new” menu in the right.
Step 2: Writing your first program “Hello, World!”
Click on the first cell and write the following code.
Press SHIFT-ENTER to execute it.
It should print “Hello, World!” below the cell.
The Hello, World! program is traditionally the first program you write in a language, which demonstrates the syntax.
Python has very little syntax and is easy to use. To compare with other languages see Wikipedia.
Step 3: Input a string from the user
Making programs interactive is fun. The first step is to get the user to type something and let your program do something with that.
s = input("What is your name? ") print(s)
Look at the code and guess what it does.
Then copy the code into a cell and execute it.
It prompted you for something – and you might type some letters, say, your name. Then what will it do? Yes, print your name.
Step 4: Your first interactive program
Actually, you have the tools now to make simple interactive programs.
Let’s try that now.
name = input("What is your name? ") print("Hello", name.capitalize()) age = input("How old are you? ") print("You are", age, "years old")
See how simple that is.
Well, you learned a few things here.
if you have a string (like, name), then you can apply capitalize() on it. What does it do?
Well, if you type your name in lowercase, then it will capitalize your name for you. If it already is capitalized, it will do nothing.
Now that is smart.
Step 5: A few methods on strings
Like capitalize() there are a lot of other methods you can apply.
In the beginning you probably worry about remember them all. I got good news for you – you do not need to. You will most likely only use a few and the others you will lookup when you need them.
But a few ones that can be funny to master are the following.
"Rune".upper() "Rune".lower() "223".isdecimal() "Rune".isdecimal()
Try to copy each one into a cell by itself and see what it does. It will most likely make sense to you.
Notice, if you copy them all into one cell in JuPyter Notebook, then it will only give the output of the last statement of the cell. Therefore, try one line at the time in one cell.
Notice, that the “Rune” is a string and the methods could be applied on variables as well.
s = "Rune" s.upper()
Step 6: Replace something in a string
My favorite and most used string method is replace(.)
Let’s just try it.
name = "Rune" name.replace('R', 'S')
Put it into a cell and execute.
It will output Sune. It will change all occurrences of R to S.
Notice, that these methods are case sensitive, meaning, that the following code.
name = "Rune" name.replace('r', 's')
It will output Rune, because there is no lowercase r to replace.
Step 7: What next?
I am happy you asked.
If this is something you like and you want to get started with Python, then this is the first lesson of a 8 hours FREE video course with full explanations, projects on each levels, and guided solutions.
Check out the first lesson here.
What about the full course?
The course is structured with the following resources to improve your learning experience.
- 17 video lessons teaching you everything you need to know to get started with Python.
- 34 Jupyter Notebooks with lesson code and projects.
- A FREE eBook with all the learnings from the lessons.
See the full FREE course page here.