Basic of Python | Tutorial

What is Python ?

We know that any program or application which is run in computer or mobile phone must be created by any programming language like C,C++,JAVA,Visual Basic,C# etc.As the time changes the programming language also change or we can say that enhance with respect to rich libraries, more functionalities, more features, more simple to write code etc. Now these days one of the most popular language having such all features available in it is called python.
 
Python is a general purpose , encrypted, high level and open source language. It is one of the simple programming language used to write codes for computer program. It is a general purpose , high level , interpreted language. It is created by Guido Van Rossum in 1989 with the thinking that everyone can easy to write and understand. In python for writing code indentation is used in the place of cursory braces. It is very powerful language . We can develop any application by using python in very less time. 

Python is used to develop desktop application, web based application, mobile application, System Software, Game development, server side programs, Computer Graphics etc.This language is also used in Space science, Data Science,Artificial Intelligence. It is basically a object oriented based language. So we can say that it is object oriented programming language. It is also interpreted language.It means there is no need to compile to convert it into computer readable program. But in the other programming language we need to convert source code into object code for make a computer readable program. It can be run in any computer so it is platform independent language.It is modular based language, so that we can use their code in another programs. It can easily run on Windows , Linux, MAC operating system etc.

Features of Python ?

  1. SIMPLE :It is very simple language. It can easily read and write. For programming in python their is no need to know about any programming knowledge or experience.
  2. INTERPRETED LANGUAGE :In other language like C, C++, JAVA etc need to compile before running or executing. Python can not be compiled. Python code are interpreted line by line at run time. That's why it is known as interpreted language. This language become slow compare to other language.
  3. PLATFORM INDEPENDENT : It can easily run on Windows, Linux, MAC operating system. Python code written in any operating system can run on another operating system. That's why it is known as platform independent.
  4. EXTENSIBLE LANGUAGE :It means if we want to add any program code of different language such as C,C++,JAVA etc than python will allow to do.
  5. LARGE AND POWERFUL LIBRARY :Large and powerful library are available in python. Modules and packages are available in python for rapid development. For different task such as GUI, Web Development, Database Connection separate modules are available so no need to write code for different task.


How to install Python

After downloading python we need to install python in your system. For installing python follow following steps.

Step- 1:

We can install python in windows in many ways by downloading web-based installer or executable installer or embedded zip files.Click on above link to download different installer according to the requirement.

Step- 2:

Download python for 64-bit windows.

Step- 3:

Run python installation wizard

Step- 4:

This screen will allow to choose the features that you want to use and goto next.

Step- 5:

This screen allow to choose some advance options and customize path or installation location. Now go for installation.

Step- 6:

Now this screen show the progress of installation.

Step- 7:

After completing installation. Now we check whether python is properly installed in our system or not. Now open command prompt and write python --version or python -V and press enter. If the output show the version that means python is installed successfully.

Best Pythom IDE for Python Development

We know python is very efficient to develop application in many domains such as Data Science or Website Development or Artificial Intelligence & Machine Learning or any other domain.For efficiently,repidly and effictively work on python we require IDE. IDE is Integrated Development Enviorment,It helps to automate the tasks and enhance the productivity and efficiency of the developer. Some of the best IDE for python development are list below.
  1. PyCharm
  2. PyDev
  3. Spyder
  4. Thonny
  5. Wing
  6. AtomIDE

Data Type in Python

In any programming language such as C, C++, JAVA etc we use so many type of data such as Integer, Character, Decimal,Boolean etc.For storing such a data a specified data type are used such as for integer data integer data type is used, decimal data decimal data type is used,for boolean data boolean data type is used. Same way following data type are used in python i.e integer, float, complex numbers, String, List, Tuple, Dictionary, set etc.

Data Type in python are classified into following:

  • Numeric
    1. Integer
    2. Float
    3. Complex Number
    4. Boolean
  • Sequence Type
    1. List
    2. Tuple
    3. String
    4. Range
  • Set
  • Dictionary


Numeric Data Type

There are three distinct numeric types such as integers, floating point numbers, and complex numbers.The introduction of these numeric types are same as give in another language like C or C++ or JAVA etc. Let we know how these numeric data type are used in python practically.
print(3)  #return 3
print(3.435) #return 3.435
print(-5) #return -5
print(2+5) #return 7
print(2+5.2) #return 7.2
print(4%2) #return 0

#define variables
first_num=2
second_num=3
print(first_num*second_num) #return 6
print(str(first_num*second_num) + " is multiply of 2 and 3") #convert number into string

Output:
3
3.435
-5
7
7.2
0
6
6 is multiply of 2 and 3

Using Integer Data Type
data_numeric=4
print((data_numeric))
Output:

4


Using Float Data Type
data_numeric=4.5
print((data_numeric))
Output:

4.5


Using Complex Data Type
data_numeric=5+6j
print((data_numeric))
Output:

(5+6j)


Using Boolean Data Type. Return (true/false)
a=5
b=6
print(a<b)
print(a>b)
Output:

True
False


OR     Return (1/0)    
a=5
b=6
print(int(a<b))
print(int(a>b))
Output:

1
0


How to convert int into float or float into int ?
int_numeric=5
float_numeric=6.5
print(int(float_numeric))
print(float(int_numeric))
Output:

6
5.0


How to convert any number into complex number ? 
int_numeric_r=5
int_numeric_i=6
print(complex(int_numeric_r,int_numeric_i))

Output:

(5+6j)


Sequence Data Type

In python sequence data type are used to store multiple values in container in organized manner just like arrays in C. In Python there are following type of sequence data type such as string,List,Tuples,set. Let we discuss how to use these data type in python.

Using List Data Type
um_list=[2,3,5,6,10]
print(num_list)
print(type(num_list))
Output:

[2, 3, 5, 6, 10]
<class 'list'>

Using Tuple Data Type
data_tuple=(12,20,10,5,8,7)
print(data_tuple)
print(type(data_tuple))
Output:

(12, 20, 10, 5, 8, 7)
<class 'tuple'>

Using String Data Type

#For next line use \n
print("Name is shailu \nAge is 40")

name="shailu" # variable name
print(name.upper()) # return SHAILU
print(name.upper().isupper()) # return True
print(len(name)) # return length of string 6
print(name[0]) # return first character of string i.e s
print(name.index("a")) # return index of a i.e 2
print(name.replace("shailu","chailu")) # replace shailu to chailu
Output:
Name is shailu
Age is 40
SHAILU
True
6
s
2
chailu
Using Range Data Type
print(range(2,10))
print(list(range(2,10)))

Output:
range(2, 10)
[2, 3, 4, 5, 6, 7, 8, 9]

If we want to print the Even number using range data type so we use 3 parameter in range such as:

print(range(2,10,2))
print(list(range(2,10,2)))
Output:
range(2, 10, 2)
[2, 4, 6, 8]


Set Data Type

data_set={12,20,10,5,8,7}
print(data_set)
print(type(data_set))
Output:

{5, 7, 8, 10, 12, 20}
<class 'set'>


Dictionary Data Type

dictionary text
dist={'1':'C-language','2':'ADA','3':'C++','4':'Python'}
print(dist)
# comment: get index or keys
print(dist.keys())
# comment: fetch values
print(dist.values())
# comment: fetch value by index or key
print(dist['2'])
# comment: get value by index or key
print(dist.get('3'))
Output:

{'1': 'C-language', '2': 'ADA', '3': 'C++', '4': 'Python'}
dist_keys(['1', '2', '3', '4'])
dist_values(['C-language', 'ADA', 'C++', 'Python'])
ADA
C++


Variables in Python


We know variable is just like a container where we put values.It is same as we use in C or C++ language. Let we know in python how we declare , define and intialize variables with the help of examples:
We will start with very basic example
let we take two variable and ADD them such as

a=2
b=3
print(a+b)

Output

5

No comments:

Post a Comment