What is Python?
Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together. Python's simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. Python supports modules and packages, which encourages program modularity and code reuse. The Python interpreter and the extensive standard library are available in source or binary form without charge for all major platforms, and can be freely distributed.
It was created by Guido van Rossum
Python consists of vast libraries and various frameworks like Django,Tensorflow, Flask, Pandas, Keras etc.
Tasks:-
Task 1:- Installation of Python
To install Python on Linux, We need to run the below commands
sudo apt-get update
sudo apt-get install python3
After installation to check the Python version need run the below command
python3 --version
Output:-
Task 2:-Data Types in Python
Numeric:-
Number stores numeric values. The integer, float, and complex values belong to a Python Numbers data type. there are 2 types of functions
type() function:- It is used to know the data type of the variable.
isinstance() function:- It is used to check an object belongs to a particular class.
Example:-
#!/usr/bin/env python
#Print integer
x = 8
print("The type of X", type(x))
#print float
y = 50.5
print("The type of Y", type(y))
#Print complex
z = 2+7j
print("The type of Z", type(z))
print(" Z is a complex number", isinstance(1+3j,complex))
Output:-
Dictionary:-
Python dictionary is an ordered collection of items. It stores elements in key/value pairs. Keys are unique identifiers that are associated with each value.
Example:-
# create a dictionary named city
city ={'WestBengal':'Durgapur','Karnataka':'Bangalore'}
print (city)
Output:-
Boolean:-
Boolean type provides two built-in values, True and False. These values are used to determine the given statement true or false. It denotes by the class bool.
Example:-
# Print a boolean
x=10
y=15
print (x>y)
Output:-
Set:-
Sets are used to store multiple items in a single variable. The set list is unordered, meaning: the items will appear in a random order.
Example:-
# Note: the set list is unordered, meaning: the items will appear in a random order.
# Rerun the file to see the change in the result.
set = {"Black", "Blue", "Green"}
print(set)
Output:-
Sequence Type:-
String:- The string can be defined as the sequence of characters represented in quotation marks. In Python, we can use single, double, or triple quotes to define a string.
Example:-
str ="Pyhton For Beginners"
print(str)
Output:-
- List:- The items stored in the list are separated with a comma (,) and enclosed within square brackets [].
Example:-
X = [4,"Saikat", "Riju",2, 3]
Output:-
Tuple:- A tuple is similar to the list in many ways. Like lists, tuples also contain the collection of the items of different data types. The items of the tuple are separated with a comma (,) and enclosed in parentheses ().
A tuple is a read-only data structure as we can't modify the size and value of the items of a tuple.
Example:-
# Create a tuple
color =('Black','Blue','White','Green')
print (color)
print(color[0])
print(color[1])
print(color[2])
print(color[3])
Output:-
Thank you for reading!! I hope you find this article helpful!!
if any query or if any correction to be done in this blog please let me know.
Happy Learning!!
Saikat Mukherjee