Python Basics in under Fifteen Minutes

I was quite happy when I learnt to program in Python, for I don’t come from a programming background. Also, python is one of the most loved and sought after skills in the programming field today. But I also heard a data scientist say, “any idiot can program! Programming is nothing. It’s the real skills that employers look for!” Ha ha, then I didn’t know how to feel about this new skill I’d learnt. Also, I’ll let you know when I hear back from this person on what they mean by “real skills”. Nonetheless, nothing changes the fact that programming in Python is both fun and powerful, so I figured I’d write on the basics of Python for anyone new to Python, for those coming from a programming background and for those who don’t.

Trust me, python is very simple and easy to start with!

Python uses indentation for a new block of code: While in some languages, you would use indentation merely to make it easier for developers or readers to read through the code, in Python, the point of indentation is more than making it easier for your eyes and understanding. It’s a way of demarcating a new block of code. Indentation must be carefully used in Python. For example, everything that happens within a for loop must strictly have the same indentation, 4 white spaces further from the “for” line to show that all those lines need to be executed when the for loop would run.

Python uses # to ignore lines of code, for us to leave comments: Comments play an important role in helping programmers communicate with one another on what we’re intending to do with a certain line or block of code. The way to leave “comments in Python is by starting a line of code with # or the hash symbol. You can also comment out multiple lines by using a # in the beginning of each of them.

Python code to show commenting and indentation

Python is an Object-Oriented Programming Language: What does that mean? Initially, I found this a bit hard to understand. It means that, in Python, everything is an “object”, a piece of data, or “code”, procedures called “methods”. And object-oriented programming languages allow you to create “abstractions” of code, which can be modified to create new instances of the same abstraction. For example, let’s consider creating a class for “NewBook”? What are the elements or aspects that define books in general? Think about it? All books would have one or more authors, a publisher or publishing company, one or more editors, one or more languages in the content, a certain number of pages, a genre (self-help or science fiction or statistics or finance or politics, something like that), cost, and such. Now, you could create an e-book or a hard copy with the same elements included because these apply to all books.

What are “args” and “kwargs”? In Python, you define a class or function by using the word “def”. If you are going to create a function that takes in two numbers as input, sums them up, and returns the output, you could define the function by saying something like this.

def sum(x, y):
return(x + y)

result = sum(5, 6)

Now, as per the definition, the function “sum” takes two values as inputs. If you give anything less or more than two inputs, you’d receive an error because Python doesn’t know what to do with it. And you need to give the inputs in the same order according to the definition. Since this function returns the sum, it doesn’t matter, (a + b) = (b + a). But if it were subtraction or division, for example, you would want to be careful with the order.
To make matters easier and keep things more accurate, you can use “kwargs” aka “keyword arguments”. You can define arguments by using “keywords” while defining a function and also define the types of data that are to be given as input. This way, the user knows clearly what the arguments are.

def coffee_consumption(name = str, type = str, number = int):
return(f"{name} has at least {number} cups of {type} a day.")

johns_details = coffee_consumption(name= "John", type= "black coffee", number= 3)
edwards_details = coffee_consumption(name="Edward", number=2,type= "mocha")
asifas_details = coffee_consumption(type= "iced latte", number=1, name= "Asifa")
print(f"{johns_details} \n{edwards_details} \n{asifas_details}")

Commonly used Data Types in Python: Guess what would happen with the “sum” function if I give two input values as “five” and “six” instead of 5 and 6? You’re not going to get the answer you expect. This is where data types come in and you need to know what are all the different data types used in Python. Whole numbers are considered “int” referring to the data type integer and decimal numbers are of the data type “float” referring to “floating point numbers”. Words like names or sentences or phrases come under the data type “str”, referring to “string”. “Lists”, as the name suggests are lists of items. For example, the list of students in a class would be a “list”.

Dictionaries, that are denoted by “dict” in Python programming, can be considered a list of “key”: “value” pairs. For example, let’s say you want to store the gender of students along with their names. In that case, you’d not require a list but a dictionary. And a “tuple” is a collection of values in which, once defined, the order of the collection or the collection itself can’t be modified. It’s called “immutable”. Booleans are used to state whether a condition is “True” or “False” (yes, the first letter is capitalized).
You can also change the data types from one to another, which again makes it very easy to program in Python, defining and changing types of objects as we go.

Conditional Statements and Loops: The “if” and “while” code works in Python the way it does in other programming languages. If you are new to programming, sometimes, you might find it tricky to decide when to use “if” and when to use “while”, but don’t sweat it in the beginning. With practice, you’ll learn your way around. Note that sometimes looping can be infinite, running with no end, and it’s through mistakes like this that we’d learn the art of coding.

Conditions and Loops in Python

Packages and Libraries You’ll have to Learn: If you are interested in machine learning, you should familiarize yourself with Python libraries such as TensorFlow, NumPy, and PyTorch. Pandas would be one of the most commonly used packages in Data Analysis if I’m not wrong. Beautiful Soup is a library frequently used in web scraping. Depending on your interests and goals, you can choose from a wide range of packages and libraries you’d enjoy working with in Python.

Now, why learn Python? Python is one of the most commonly used languages in automation, data analysis, and data visualization. If you’re into data science, you’d benefit a great deal by learning to code in Python. Also, it’s relatively very simple to learn, even for beginners or those who are new to programming. Even if programming is only a hobby or new interest, chances are high that you’d still enjoy working with Python.




This is a place where we can discuss interesting new perspectives and find answers and explanations for all things in the world of design and development.

Recommended from Medium

Introduction to Automation Testing

Am I Too Late to Learn Python?

PI Planning/ Big Room Planning / Tribe Planning is not an Indian FAT WEDDING !!!

EYWA platform Alpha testing statistics.

Large scale Flutter applications

Python Packages — A beginners guide

Still using witchcraft to foresee IT risks to Business Continuity?

Tutorial 7 : OOPs in Python — super() function

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Lakshmi Prakash

Lakshmi Prakash

A conversation designer and writer interested in technology, mental health, gender equality, behavioral sciences, and more.

More from Medium

Python for Data Science — All about Lists

NumPy — Mathematical Computing with Python

NumPy - Mathematical Computing with Python

This is the standard Data Science workflow

Exploratory Data Analysis in Python, Using Just 9 functions