Introduction To Python

Introduction To Python

Getting Started with Python

🌠What is Python?

  • Python is Open source, general purpose, high-level, and object-oriented programming language.

  • Guido van Rossum developed Python

  • Python consists of vast libraries and various frameworks like Django, Tensorflow, Flask, Pandas, Keras, etc.

⚒How to Install Python on the UBUNTU Server

Now let's see how to install Python before that let's update our Ubuntu server as

sudo apt-get update

This will update our server with the latest packages.

Now let's install Python & check the version of it

sudo apt install python3
python3 --version

Also, install pip for python sudo apt install python3-pip.

It enables the installation and management of third-party software packages with features and functionality not found in the Python standard library.

sudo apt install python3-pip

🌠Data Types in Python

A classification or categorizing of data elements is known as data types. It means the type of value that indicates the different types of operations that can be carried out on a specific set of data. In Python programming, variables are instances (objects) of these classes, and data types are truly classes because everything is an object.

1.Numeric Data Types

In Python, numeric data types are used to represent numerical values. There are three primary numeric data types in Python:

👉int: Represents integers (whole numbers). Example: j = 3

👉float: Represents floating-point numbers (numbers with decimal points). Example: k = 3.14

👉complex: Represents complex numbers. Example: z = 3 + 2j

2.Sequence Types

Sequence types are a class of data types in Python that symbolize collections of elements in an ordered manner. Every element in a sequence has a distinct index or position, with the first element's index or position being 0. Python has several built-in sequence types, such as:

👉str: Represents strings (sequences of characters).

Example: text = "Welcome to India"

Lists and tuples are similar in that they are sorted lists, but tuples are unchangeable once they are created. In brackets are used to define tuples.

👉list: Represents lists (ordered, mutable sequences).

Example: my_list = [1, 2, 3]

👉tuple: Represents tuples (ordered, immutable sequences).

Example: my_tuple = (1, 2, 3)

3.Mapping Type

In Python, a mapping type is a built-in data type that represents a collection of key-value pairs. Each key in the mapping is associated with a value, and you can use the key to retrieve the corresponding value.

The primary mapping type in Python is the dictionary, which is denoted by curly braces {} and consists of key-value pairs enclosed in those braces. Keys within a dictionary must be unique and immutable (e.g., strings, numbers, or tuples), while the corresponding values can be of any data type.

👉dict: Represents dictionaries (key-value pairs).

Example: my_dict = {'name': 'vyankatesh', 'age': 22}

4.Set Types

set: A set is created by enclosing a comma-separated sequence of elements within curly braces {} or by using the set() constructor. Sets automatically eliminate duplicate elements, and they are unordered, which means that the elements are not stored in any particular order.

👉Represents sets (unordered collections of unique elements).

Example: my_set = {1, 2, 3}

5.frozenset

A frozen set is similar to a regular set, but it is immutable, meaning you cannot add, remove, or modify its elements once it is created. To create a frozen set, you can use the frozenset() constructor.

Represents immutable sets.

Example: my_frozenset = frozenset([1, 2, 3])

6.Boolean Type

In Python, the Boolean type, often referred to as a "bool," is a built-in data type that represents one of two possible values: True or False. Booleans are primarily used for making decisions and controlling the flow of a program through conditional statements, such as if statements and loops.

👉bool: Represents Boolean values (True or False).

Example: is_valid = True

7.Binary Types

In Python, binary types refer to data types and representations used to work with binary data, which consists of sequences of 0s and 1s. Binary data is often used in various applications, such as reading and writing binary files, encoding and decoding data, and handling low-level data manipulation.

👉bytes: Represents immutable sequences of bytes.

Example: data = b'Hello'

👉bytearray: Represents mutable sequences of bytes.

Example: data = bytearray(b'Hello')

8.None Type

In Python, None is a built-in constant representing the absence of a value or a null value. It is used to indicate that a variable or expression does not have a meaningful value or that a function does not return a specific result.

None is often used to initialize variables when you don't have an actual value to assign to them, and it can be used to check if a variable has been assigned a value

👉NoneType: Represents the None object, which is used to indicate the absence of a value or a null value.

Example : value = None

Congratulations 🎉 ! You learn about How to install Python on Ubuntu & different data types of Python

I hope you enjoy the blog post!

If you do, please show your support by giving it a like ❤, leaving a comment 💬, and spreading the word 📢 to your friends and colleagues 😊

Did you find this article valuable?

Support Vyankateshwar Taikar by becoming a sponsor. Any amount is appreciated!