Site icon Console Flare Blog

Learn Python Basics In 5 Minutes

Python needs no introduction. In the world of programming language, python is emerging as a rock star, a super-hero. But why is Python so popular? To understand this, you must know programming language is a medium to achieve the desired result. Now if something can be done easily, quickly with python, you will not go for any other language.

In Google there is a saying :

Python Where We Can , C++ where We Must.

But the best part of python is its easiness. Let’s learn the basics of python, so you can start your journey.

Install Python

You can install python from python.org.

python

Once you have installed python, you need an editor to write codes and execute your programs. There are various editors to choose from. But we are going to go with PyCharm.

Install PyCharm

You can install PyCharm from its official site.

PyCharm

Click on Black Download Button to download the Community version of PyCharm, It is free and you will not have to pay any charge.

Once you have downloaded Python and PyCharm, You are ready to go.

How To Write Your First Program

Click On PyCharm that you have just downloaded, A pop-up window will appear.

Now that you know how to run PyCharm, Let’s dive into the basics of Python.

Data Types

Python offers a lot of data types such as :

We will cover these data types ahead in this article.

Variables

You do not need to declare variables before using them or declare their type.

age = 25

Here age is a variable that is assigned a value 25. So the data type of age is an integer.

How to Print in Python

We use a simple function print, to print anything on the console screen.

print(age)

Before anything let’s go through each data type one by one.

integer (int) :

Any number positive or negative with no decimal value is integer data type.

1,2,-1,-198

To convert any a value to an integer data type we use int() function

int(‘123’)

float (float) :

Any number positive or negative with a decimal value is a float data type.

1.5,2.4,-1.3,-198.45

To convert any a value to float data type we use float() function

float(‘123’)

string (str) :

String is a collection of characters written underquotes.

‘medium’, ’python’, ’123’

To convert any value to string data type we use the str() function.

str(123)

boolean (bool) :

Data that is either True or False.

True , False

To convert any a value to boolean data type we use the bool() function

bool(1)

lists (list) :

List is a collection of values of different data types enclosed within square brackets [].

[1,2,3,4,5,98,5]

Sets (set) :

Set is a collection of unique values of different data types enclosed within curly brackets {}.

{1,2,56,78}

Tuples (tuple) :

Tuple is a collection of values of different data types that cannot be changed enclosed within curly brackets ().

(1,2,56,78)

Dictionary (dict) :

Dictionary is a collection of key : value pair enclosed within curly brackets {}.

{‘name’ : ‘Console Flare’ , ‘city’ : ‘ Noida ’}

User Input

To take input from user, we use input() function in python. Let’s do a simple program to understand use of input.

name = input(‘Enter Your Name : ’)

company = input(‘Where do you work ? ’)

print(‘I am’ , name, ’and I work in’ , company)

input() function always takes input from user in string data type, so we need to convert values from user to desired data type to perform the operation.

length = int(input(‘Enter Length : ’))

breadth = int(input(‘Enter Breadth : ’))

print(‘Area is ’, length * breadth)

code

Loops

Loops are used to perform repetitive action.

for i in range(3):

print(‘medium’)

Functions

Functions are piece of code that does a particular task. To define a function in Python, we use def keyword.

def funcname(parameters):

statements

For example , let’s say we want to create a function to add two numbers:

def add(x,y):

print(x+y)

Calling a Function

add(3,2)

How To Learn Python The Right Way?

Now that you have learned basics of python, Let’s know more about python.

When you are learning a programming language, your goal must be clear.

Why do you want to learn this programming language ? What you will be doing after you master this language ? You must find a reason to learn this language. Every language has one application that surpasses other.

Python , now a days , is used for Data Science. Data Science , not to tell, is a booming field. You can go through this article to know salary trends for Data Scientists in India.

If you want to put your python knowledge to best use, Apply it in Data Science. To learn Data Science, you can connect to us.

We are Console Flare. We have successfully placed more than 1000 students and IT Graduates to become Data Scientist.

We also provide webinars for you to join and know more about Data Science.

You can connect to us at ConsoleFlare and Become a Data Scientist in just 5 Months.

Exit mobile version