Python Tutorials for Absolute Beginners: Part 1

Darshit Suthar
Analytics Vidhya
Published in
5 min readDec 8, 2020

--

Hello World!!

This is my very first blog and in this blog, we will be exploring the basic for python programming. So, without any further ado, let's dive into it….

What is Python?

Python is a powerful general-purpose and a high-level programming language and has got simple syntax that makes it easy to use.

Since it has simple syntax, it allows developers to write programs with fewer lines of code compared to other programming languages and this makes it more fascinating.

Python is an interpreted language.

Wait…what does interpreted mean?

According to the dictionary…

interpreter meaning

In case of python, code written by humans are not understood by machines, so, every time a program runs, it is the interpreter that translates code into machine-readable byte code.

Where can you use it?

  • Web Development
  • Data Science
  • Data Engineering
  • Creating Software Applications
  • Game Development and many more.

Simple Installation Steps

Installing python is pretty much simple, just follow the steps given below

Linux

Open terminal and type: sudo apt-get install python3

Enter the password and this will install python on Linux system

Windows

Installing python on windows is pretty much simple, just follow the steps given below

Go to https://www.python.org/downloads/ and click on the download button.

Run/Double-click the downloaded python executable file and follow the steps given below:

By now you must have installed python on your machine. Let’s start learning!

Comments in Python

Comments play an important role in programming, they are generally avoided by the interpreters and compilers. Comments can be used to describe your code and make your code more readable and understandable.

For a single line comment, we can use the #(hash) symbol to start commenting and for a multi-line comment, we use ‘’’ symbol at the beginning and end of the line.

Variables

Variables are basically names that you assign to a memory location where you can store some value. If compared with languages like Java, C or C++, variables in those languages would bind the variable with a specific data type, like if you have a variable of integer type, you can only have data of integer type in that variable… But in python, you have the flexibility to handle the variables by changing the value and data type of that variable.

Python handles several data types, in this blog, we will be focusing on strings, numbers, Booleans, lists, tuples, dictionary, date and time.

String:

It is a sequence of characters that can be a combination of letters or numbers or some symbols. To define a string, we enclose the string in single or double inverted commas.
To fetch a specific character from a string just type the name of the variable with its index (index is a numerical representation of items that starts from zero).
Concatenating string: To concatenate or combine, two or more strings we can use the “+” operator.

Some of the most used string methods:

upper(): this method converts the string to uppercase

lower(): this method converts the string to uppercase

replace(): this method replaces a specified value with a specific value

len(): this method returns the length of the string

count(): this method returns the number of times a specified value occurs in a string

Numeric Data type:

Integer (int): Integers are whole numbers without a decimal point. They can be positive or negative.

Float: floating-point numbers are real numbers, they are written with a decimal point that segregates the integer from the fractional numbers.

Complex numbers: Complex numbers are pairs of real and imaginary numbers. It is of the form ‘a + bJ’.

Boolean Data Type:

when you compare any two values, python returns the answer in Boolean data type, True or False.

List:

A list datatype is used to store multiple items in a single variable. Items in the list are indexed and start with zero. To create a list, we put the elements inside the square bracket([ ]). Lists are mutable, this means you can change the elements/ items of the list.

Tuples:

Tuples are similar to a list, it is used to store multiple items in a single variable but they are immutable (elements in tuples are unchangeable). Items in tuples are indexed and start with zero. To create a tuple, we put the elements inside the round brackets(( )).

Dictionary:

In a dictionary, you store the data in a key-value pair. A colon(:) separates a key from its value and all are enclosed in curly braces({ }). Values in dictionaries are mutable this means, the values are changeable.

Date and Time:

To get date and time in python, we need to import the datetime module.

Type conversions

Type conversion helps in converting one data type to another which is very useful in programming.

Conditional Statements

Conditional statements are used to perform actions based on whether a condition is true or false.

The if-else has the following syntax:

If the condition1 is true the statement given inside the if is executed but if the condition1 is false the statement from the else part is executed.

Let's see some examples…

Loops

Python provides two types of loops, the for loop and the while loop. These loops iterate over statements that allow a block of code to be repeated several times.

For loop:

For loop is used to iterate over a list, tuple or a string. For loop executes one statement per item in a list, tuple or string.

While Loop:

While loop executes a set of statements as long as a condition is true.

Functions

A function is a group of statements that performs a specific task. It helps in avoiding code repetition and makes the code reusable. To create a user-defined function we use the def keyword followed with the function name.

Syntax: def functionName(parameters):

Let’s see a good example to add/ remove items in a list using user-defined functions…

Woah!

You’ve learned a lot of basics about python; the variables, datatype, loops, functions and so much.

But we ain’t done here, soon I’ll be posting the part 2 that is the advance python so stay tuned!

Following are some of the best IDE’s that can be used for Python programming:

  • IDLE
  • PyCharm [I personally like it ❤️]
  • Visual Studio Code
  • Spyder

--

--