Python Notes
Python Notes
Features of Python
Python used
Python has wide range of libraries and frameworks widely used in various fields
such as machine learning, artificial intelligence, web applications, etc. We define
some popular frameworks and libraries of Python as follows.
Variables
A variable is the name given to a memory location. A value-holding Python
variable is also known as an identifier. Variable names must begin with a letter
or an underscore, but they can be a group of both letters and digits. The name of
the variable should be written in lowercase.
Rules of Variable
Python Data Types are used to define the type of a variable. It defines what type
of data we are going to store in a variable. The data stored in memory can be of
many types. For example, a person's age is stored as a numeric value and his or
her address is stored as alphanumeric characters.
Numbers
Numeric values are stored in numbers. The whole number, float, and complex
qualities have a place with a Python Numbers datatype. Python offers the type()
function to determine a variable's data type. The instance () capability is utilized
to check whether an item has a place with a specific class.
a=5
print("The type of a", type(a))
b = 40.5
print("The type of b", type(b))
c = 1+3j
print("The type of c", type(c))
print(" c is a complex number", isinstance(1+3j,complex))
Output
○ Int: Whole number worth can be any length, like numbers 10, 2, 29, - 20, -
150, and so on. An integer can be any length you want in Python. Its worth
has a place with int.
○ Float: Float stores drifting point numbers like 1.9, 9.902, 15.2, etc. It can
be accurate to within 15 decimal places.
○ Complex: An intricate number contains an arranged pair, i.e., x + iy,
where x and y signify the genuine and non-existent parts separately. The
complex numbers like 2.14j, 2.0 + 2.3j, etc.
Sequence
The plus (+) sign is the string concatenation operator and the asterisk (*) is the
repetition operator in Python.
Example:
list1 = [1, "hi", "Python", 2]
#Checking type of given list
print(type(list1))
# List slicing
print (list1[3:])
# List slicing
print (list1[0:2])
Output
[1, 'hi', 'Python', 2]
[2]
[1, 'hi']
[1, 'hi', 'Python', 2, 1, 'hi', 'Python', 2]
[1, 'hi', 'Python', 2, 1, 'hi', 'Python', 2, 1, 'hi',
'Python', 2]
Tuple
A tuple is like a list. Tuples, like lists, also contain a collection of items
from various data types. A parenthetical space () separates the tuple's
components from one another.
Example:
tup = ("hi", "Python", 2)
# Checking type of tup
print (type(tup))
# Tuple slicing
print (tup[1:])
print (tup[0:1])
Output
<class 'tuple'>
('hi', 'Python', 2)
('Python', 2)
('hi',)
('hi', 'Python', 2, 'hi', 'Python', 2)
('hi', 'Python', 2, 'hi', 'Python', 2, 'hi', 'Python', 2)