Starting out with Python – Step by Step Guide

Posted by Marta on December 29, 2020 Viewed 2316 times

Card image cap

Starting out with python or programming can be intimidating. So many resources that it is difficult to know the right path. I will start introducing the basic concepts, print, variable, input, conditionals(if-else), for loops, while loops, functions, import modules and some code challenges. Then some data structures and object oriented programming.

The concepts are the same for most programming languages. In other words, all these concepts are transferable for any language. Python is a good language for beginners as it is quite concise, less code to do something. Java is also a good language a bit more complex. My advice would be start programming with Python, you can always learn Java later. Once you know one language learning the second one is much easier because you understand all programming basics.

Start Programming with the basics

The basics concepts are the same for most programming languages so no matter what language you use to start learning, the basic concepts will be useful. It will speed up the learning of a second language.

These is an introduction to the fundamental concepts that you should learn:

  • print: It is used to display text in the screen.This is important because is the simplest way in which a program can communicate with you, so you know what the program is doing.
print('Message to print on the console')
  • Variables: you can think of variables as containers that hold values. You can refer to this value using the variable. The variable will be assigned a place in memory where the value is saved.
    There is also the concept of type in some languages which basically defined if your value is a number, or text, true or false. This is useful because it allows you to know what you can do with the variable. For instance, if it is a number, you can add another number.
name_variable = 'Marta'
number_variable = 2
decimal_num_variable = 2.05
  • input: Input means your program will request you to enter a value. For instance, the code below request that you to enter your age and then It will display a message
age = input('Please enter your age:')
print('The age entered is: ' + age)

Learn flow control basics

  • Conditionals(if-else): Make decision or following different action paths based on a condition is key in programming. Basically that means checking a condition, condition met? then perform an action, otherwise, do something else.
    For example, the code below request your age, if the age entered is less that 18 , the program will reply, “You are under 18”.
    Otherwise the program will display “You are 18 year old or older”.
if(age<18):
 	print('You are under 18')
else:
	print('You are 18 or older') 
  • Loops: Loop are used when you want to repeat an action. Depending on how many times you would like to repeat your action, you will use a FOR loop or a WHILE loop. If you know the fixed number of times  you will perform the action, then FOR loop is the correct choice. If you like to repeat some action while some condition is met, then use a WHILE loop.
print('Multiplication Table')
for index in range(0,11):
  print('2 x '+ str(index) + ' = ' + str(2*index)) 
  
# Same with a while loop
index = 0
while(index<11):
  print('2 x '+ str(index) + ' = ' + str(2*index))
  index = index + 1
  • Function: Function is a set of instructions that you can be labeled with any name you like and reuse.
def print_multiplication_table(num):
  print('Multiplication Table')
  for index in range(0,11):
  	print(str(num)+ ' x '+ str(index) + ' = ' + str(num*index)) 
    
print_multiplication_table(2)
print_multiplication_table(4)
  • Modules: A module is code already written by someone else that you can reuse. For instance, let’s say you have the number 3.87979797 and you would like to round to the second decimal point. You can write some code yourself to do this, or you could import a module that covers this functionality and just used it. This is really useful in professional development. There are thousand of libraries out there, so no matter what problem you are solving, probably there is a library you can use

Practice: Find code challenges

Once you understand the basics concepts and know how to use them in your preferred language, it is time to practice. There are many sites on the internet where you can find code challenges for beginners and start practicing. One that I would recommend is HackerRank

https://www.hackerrank.com/

There are thousand of exercises for different languages and levels and you don’t need to install any software in your computer. Just sign up, completely free, and you are ready to start. Actually companies use this sites to send code challenges to software engineer candidates, so it is the perfect place to start.

What’s next? Data Structures and Object Oriented Programming

You picked your language, you understand the basics and you have done some coding challenges and you are confident about what you learnt. Where do you go from there?


Time to learn data structures! but…what are data structures? It’s basically a variable, but more complex. Instead of containing one value, it might contain a several values. Those values might be same type, for instance, all numbers, or texts. You can also organise them in different ways, order them alphabetically, or save them by the order in which you received them. Some very common data structures are arrays, list, queues, stacks , tree and there are more.

Find out more about data structures

After covering data structures, next stop will be object oriented programming. OOP basically means that instead of using just the variable types provided by python, also known as primitives, you will create your own types. For instance you can create an object Person, which will contain two data, the name and the age.

Find out more about object oriented programming

Which programming language should I learn?

Python and Java are both really popular languages, and both are in huge demand. I have been a java developer for 10 years and I constantly get calls from recruiters offering jobs. Plus it is quite well paid. If you learn both languages, or one of them, I can assure you, you will have a job for many years, unless an asteroid falls on earth and computers disappear!

Although both are good I will start with Python, just because it is much more intuitive, therefore you will learn it faster. Plus it is more concise, so less code to achieve the same thing.Once you are confident with python, you can always learn Java.

The reason I advise to consider learning two languages is that when you learn another language your understanding will expand, since you will see two ways of achieving the same thing. I know it is a bit more work, however it’s worthy since your knowledge will be more solid. Plus it shows your interest in programming. Quite impressive in prospect of your future interviews.

I hope this article gave you a clear roadmap of the steps you can follow to start programming. I think this is achievable in 1-3 months. Please let me know if you try this. How long did it take you? Or have you already done it, if so how did it go? Please feel free to leave comment below sharing your experience! 🙂

What’s next?

Starting out with Python https://img.youtube.com/vi/pd7nlWy8IMA&t/default.jpg Python Programming Fundamentals for absolute beginners covered in 30 mins 2020-07-22 https://youtu.be/pd7nlWy8IMA&t

If you like the article and you would like to be notified when I publish more articles feel free to follow, give it a like or subscribe.

More Interesting Articles

Project-Based Programming Introduction

Steady pace book with lots of worked examples. Starting with the basics, and moving to projects, data visualisation, and web applications

100% Recommended book for Java Beginners

Unique lay-out and teaching programming style helping new concepts stick in your memory

90 Specific Ways to Write Better Python

Great guide for those who want to improve their skills when writing python code. Easy to understand. Many practical examples

Grow Your Java skills as a developer

Perfect Boook for anyone who has an alright knowledge of Java and wants to take it to the next level.

Write Code as a Professional Developer

Excellent read for anyone who already know how to program and want to learn Best Practices

Every Developer should read this

Perfect book for anyone transitioning into the mid/mid-senior developer level

Great preparation for interviews

Great book and probably the best way to practice for interview. Some really good information on how to perform an interview. Code Example in Java