Day 13: 90DaysOfChallenge

Day 13: 90DaysOfChallenge

Basics of Python

What is Python?

Python is a widely used general-purpose, high level programming language. It was created by Guido van Rossum in 1991 and further developed by the Python Software Foundation. Its syntax allows programmers to express their concepts in fewer lines of code.

Uses:

It is used for building Web Applications, handling big data and performing complex mathematics operations, connecting to databases system for reading and modifying files, or used for building production-ready software.

Importance:

Python uses very simple language hence, it's syntax is easy to understand and write. It works on different platforms like Windows, Linux, Mac, etc. It has syntax that allows developers to write programs with fewer lines than other programming languages like Java, C, C#, etc.

Installation:

  • You can install Python in Windows using the official link -

    Download Python

  • In Ubuntu, you can give the below command to install Linux-

    apt-get install python3.6

Data types in Python

Data types are the classification of data items. It represents the kind of value that tells what operations can be performed on a particular data. Data types are classes and variables are instances (object) of these classes. The following are the standard or built-in data types in Python:

Python type() Function

We use the type() function to define the values ​​of various data types and check their data types. Ex-

x=20
y=201.32
z="Python"
a=[2,3,4,1,2]
b=(23,43,3,"python")
c={33,1,5,"java"}
print(type(x))
print(type(y))
print(type(z))
print(type(a))
print(type(b))
print(type(c))

Output:

<class 'int'>
<class 'float'>
<class 'str'>
<class 'list'>
<class 'tuple'>
<class 'set'>

Numeric Datatype

It represents the data that has a numeric value. A numeric value can be an integer, a floating number, or even a complex number.

  • Integer - It represents numeric data i.e. positive or negative whole numbers, like 4, 5, or -1.

  • Float - It represents rational numbers i.e. numbers containing decimal figures, like 2.32, 4.90 or -109.20.

  • Complex - Complex number is represented by a complex class. It is specified as (real part) + (imaginary part)j like – 2+3j

Sequence Datatype

The sequence Data Type in Python is the ordered collection of similar or different data types. Sequences allow storing of multiple values in an organized and efficient fashion. There are several sequence types in Python –

  • String - It is a collection of alphabets, words, or other characters. It is created by enclosing a sequence of characters within a pair of single or double quotes. Ex- s = "Python"

  • List - Lists are used to store collections of heterogeneous data and is an in-built datatype in Python. It is mutable means the values can change even after its initialization. The values are written inside square braces. Ex- list = [2, 3, "python", 32]

  • Tuple - Tuple is also used to store collections of heterogeneous data but it is immutable means once initialized it's values cannot be further changed or modified. It is very fast as compared to list. It is written inside round brackets. Ex- tuple = ("Shilpi", 32, "30")

Boolean Datatype

Data type with one of the two built-in values, True or False. Boolean objects that are equal to True are true, and those equal to False are false.

Set Datatype

It is an unordered data structure that stores unique values. It is written inside curly braces. It is mutable means the values can change even after its initialization. Ex- set = { 21, 32, 34, 43}

Dictionary Datatype

It is made of key-value pairs. Key is used to identify the item and the value holds the value of the item. Key has to be unique value as it is used as an identifier and value can store repeated values. It is written inside curly braces. Ex- dict = {"student1" : 20, "student2" : 30}

Thanks for reading!

~Shilpi