Python is a higher-level programming language that is being used widely in various modern software development fields. 

Python's relatively flat learning curve makes it one of the most popular language among beginners to programming.  In this article, we will discuss some of the questions that people who want to learn Python normally ask or have in their minds.

How long does it take to learn Python?

Programming is an ever-changing field, so there is no time that will come when a person will have fully learned Python or any other language for that matter. As we are speaking features are being added to python and its existing libraries and frameworks and new libraries/frameworks are being created.

But let us for a moment assume that learning python refers to the time it will take until you can write production-ready Python code.  The time taken will vary depending on various factors. Some of such factors are as listed below:

  • Programming background - A person who has some background in programming or has already worked with other programming languages will learn Python in lesser time as compared to someone to whom python is the first language.
  • Dedication - Programming in general is a mentally-demanding field, the time dedicated to learning Python will directly affect the rate at which the learner will grasp some intricate details about the language.
  • Getting help - You will sometime get stuck in your journey to learn Python. But that shouldn't be a thing to demotivate you. It is very likely that very same problem has been encountered by another developer. The good news is that today you can get a lot of solved issues online with the help of google and communities like StackOverFlow

Is Python easy to learn and use?

Compared to some lower-level languages, Python is relatively easy to learn and use.

Python syntax is very human-friendly, it is often said to have a clean-syntax.  This makes Python code easier to read and understand  than those written in some other languages.

The higher-level and less-restrictive nature of Python allow developers to focus more on application-building than on low-level implementation details. This in turn makes it easier to turn an idea quickly into a production-ready application.

Which languages do I need to learn before learning Python?

It is not a prerequisite that python beginners need to have a background in other programming languages before they learn Python. Python is a first-language for a lot of developers, and it is even being taught in a lot of schools in introductory courses to programming and computer science.  

However, having a background in other languages may prove beneficial when learning Python. This is because most programming languages share same concepts even though implementations of such concepts may vary.

Should I learn Python 2 or Python 3?

There are two main distributions of Python i.e Python 2 and Python 3. The two distributions are not compatible, this means that code written for either will generally not work in the other.  Python 3 is currently the major distribution of Python, it was introduced in 2008 with an aim of rectifying some major design flaws of Python 2.  It is now okay to assume that anyone talking about Python is referring to Python 3.

In January 1st 2020, the Python software foundation announced that there will be no more improvements for Python 2. As of today,  Python 2 is mostly only being used  by legacy applications that were using it before Python 3 was introduced.

As a beginner, you should have no reason to learn Python2.

Where is Python being used?

Python is currently one of the most used languages in modern software development. It is being applied in all sort of applications. It is almost impossible to single out a Programming domain where Python is not being applied.

Python's highly-extensible nature has led to creation of a lot of third-party libraries and frameworks allowing Python to be used in almost any imaginable programming domain. 

A lot of top software companies like Google, Uber, Pinterest, Facebook, Instagram, Quora and many others are using Python extensively in some of their operations.

The following are some of areas where python excels:

Machine learning

Machine learning is a branch of artificial intelligence that focuses on making computers to gradually learn/improve accuracy with experience. 

Some machine learning Python frameworks includes:

Web development

Web development is the creation of web applications that can be accessed through the internet or an intranet system.

The following list highlights some popular web-development libraries and frameworks in python:

Data Science

Data science is the collection, organization and manipulation of data using statistical methods.

Some data science python libraries includes:

Is Python compiled or interpreted?

Python is formally categorized as an interpreted language.

All installations of Python comes with an interpreter which converts the higher-level Python code into instructions that a computer can understand.

Interpreted languages like Python are generally more higher-level and easier to use than compiled languages. However, this is at the cost of slight reduction in speed, but this only becomes an issue for very specific programming scenarios that require very high computation speeds.

Is Python Object-Oriented?

Python is an object-oriented language but it also supports other programming paradigms like functional  and modular programming.

OOP in Python is implemented through classes, a class acts is a blueprint for creating objects.

Literally speaking, everything in Python is an object.

How do you write hello world program in Python?

A hello world program is usually considered the simplest program in a given programming language. It simply displays the words "Hello, World!" to the console.

The following shows a hello world program in python:

hello word program

print('Hello, World!')

The print() in the above example, is a builtin function that is used to display text to the console. basically, texts in Python are enclosed either in single quotes as in 'text' or double quotes as in "text". In the above example, we passed "Hello, World!" to the print() function, the quotes are note included in the printed text 

In addition to print(), Python has more builtin functions. To use builtin functions, we just have to call them without having to perform any extra imports or installations.

How do you declare variables in Python?

Variables are named memory locations where we can store values in our program. They can be thought of as data containers, where each container has a name and a value stored in it. The name of the variable is also called an identifier. We can access the value stored in a given variable using the variable's identifier.

To declare a variable in python we use the variable_name = value syntax. Where variable_name is the name/identifier of the variable and value is the data item that will be stored in the memory location associated with the variable.

variable declaration

name = 'John'
age = 10

print("your name is ", name, ", you are ", age, ' years old.')

In the above example, we declared two variables, name and age. The name variable stores text value i.e 'John',  while the age variable stores an integer value i.e 10. We used the print() function to display some information about the variables.

Python variables can hold values of varying types, this means that we can assign a value of another type to a given variable regardless of the type of value it originally held. languages that allow this behavior are said to be dynamically-typed, this is in contrast statically-typed languages where a variable can only hold values of a particular type specified at declaration. 

Is Indentation mandatory in python?

Indentation is not only a mandatory feature for separating blocks of code in Python,  it is also mandatory that statements of a particular block be at the same level of indentation. Incorrect indented code will cause the IndentationError exception to be raised.

Statements in  in the outermost level/global statements, should begin at the leftmost level of indentation.

incorrectly indented program 

   name = 'John'

The above example, raises an error because the declaration of the variable name does not start at the leftmost level of indentation.

Unlike other languages, Python does not use curly braces, to indicate a block of code, it uses indentation. Blocks of code, includes, conditional statements, loops, functions, classes, etc.

The header of any block is always terminated with a colon(:) and the subsequent statement are indented with a level deeper than that of the header. the following example shows a conditional statement.

a = 7

if a % 2 == 0: 

As you can see above, the header of the if and the else blocks are terminated with a colon. Python expects that the subsequent statements after the colon to be indented at a deeper level, failure to which will lead to an IndentationError exception.

this leads to an IndentationError

a = 7

if a % 2 == 0: 

How do you create a loop in Python?

Loops allow us to perform an action repeatedly until a condition fails. Python supports two basic type of loops i.e for loop and while loop.

Loops are blocks, this means that in their definition, the header should be terminated with a colon, and subsequent statements after the header should be indented.

In the following examples we will declare both for loop and while loop to display integers from 0 to 9.

A simple for loop 

for i in range(10):

The above for loop will print the values from 0 to 9, to see more on how for loops work see for loops in Python.

The equivalent while loop to the previous for loop  example is as shown below:

a simple while loop 

i = 0
while i < 10:
   i += 1

The for loop and the while loop are normally suitable in contrasting scenarios. The for loop is typically applied in cases where we know in advance how many times we want  to repeat an action, thus the above example is most suitably written using the for loop approach because we know how many times we need to repeat to get values from 0 to 9. The while loop, on the other hand, is more suitable in cases where we are uncertain on how many times the loops should repeat, this is for example when the conditions are based on variables that may change.

How do you define a function in Python?

Function definition can be subdivided into two parts, the header and the body. The header signals the start of a function, while the body is where the logic of the function goes.

The header consists of the def keyword, followed by the name of the function, followed with parenthesis which may include parameters to specify the arguments/inputs that the function requires, and the header is terminated by a colon just like any other block of code.

To use a function, we have to call it. Calling a function involves using its name followed by the parenthesis with the necessary arguments as defined in its header. 

In the following example we will define a function called add that will take two numbers as arguments/inputs and then display their sum.

def add(a, b): #header
  print("%s + %s = %s"%(a, b, a + b)) #body

add(10, 20) #calling

Some useful resources that dives deeper into Python functions: