Python Basics

Python Basics

ยท

5 min read

What is Python?

Python is a high-level, interpreted programming language that is used for a variety of purposes such as web development, data analysis, artificial intelligence, machine learning, automation, and more. It was first released in 1991 by Guido van Rossum and has since become one of the most popular programming languages in the world. Python's syntax is designed to be easily readable and it has a vast standard library that provides support for a wide range of tasks. It also has a large and active community of developers who contribute to its development and support.

Some of the notable features of Python include dynamic typing, garbage collection, and support for multiple programming paradigms such as object-oriented, functional, and procedural programming. Python can be run on multiple platforms including Windows, macOS, and Linux.

  • Python has many features that make it a popular programming language for a variety of applications. Here are some:
  1. Easy to Learn and Read: Python has a simple and easy-to-understand syntax which makes it easy to learn and read. It has a high-level programming approach which makes it easy to express complex ideas in fewer lines of code.

  2. Open Source: Python is an open-source programming language which means that its source code is available for anyone to use, modify, and distribute. This makes it an attractive choice for developers who want to create free or low-cost software.

  3. Cross-platform: Python can run on multiple operating systems like Windows, Linux, and macOS, which means that code written in Python can be easily ported between platforms.

  4. Large Standard Library: Python has a vast standard library that provides a rich set of modules and functions that can be used to accomplish various tasks like string processing, file input/output, network programming, and more.

  5. Object-oriented: Python supports object-oriented programming (OOP) which is a programming paradigm that emphasizes the use of objects to represent data and methods to operate on that data.

  6. Interpreted: Python is an interpreted language, which means that it does not need to be compiled before running. This makes it easy to write and test code and to quickly iterate and make changes to code.

  7. Dynamic Typing: Python is dynamically typed, which means that variable types are determined at runtime rather than being declared beforehand. This allows for more flexibility in coding.

  8. High-level Data Structures: Python has built-in data structures like lists, dictionaries, and sets that make it easy to work with data in a structured manner.

  9. Extensible: Python can be extended using modules written in other programming languages like C and C++, which provides additional functionality and performance.

  10. Community Support: Python has a large and active community of developers who contribute to its development and support. This makes it easy to find help and resources when needed.

How to install Python?

To install Python on your computer:

  1. Go to the official Python website (python.org/downloads) and download the latest version of Python that is compatible with your operating system.

  1. Open the installer file and follow the instructions to install Python. During the installation process, you can choose to customize the installation by selecting the optional features you want to install.

  2. Once the installation is complete, you should be able to open a command prompt or terminal and type "python" to launch the Python interpreter. You can test your Python installation by typing "print('Hello, World!')" into the interpreter and pressing Enter. If everything is working correctly, you should see the message "Hello, World!" printed on the console.

  3. Additionally, you may want to install a code editor or integrated development environment (IDE) to write and execute Python code. Some popular options include PyCharm, Visual Studio Code, and Sublime Text.

That's it! You now have Python installed on your computer and are ready to start writing Python code.

Python installation on Ubuntu 22.04

  1. Setting up python3
$ sudo apt update
$ sudo apt -y upgrade
$ sudo apt install -y build-essential libssl-dev libffi-dev python3-dev

Check the python version with the python3 --version.

  1. Setting Up a Virtual Environment
$ sudo apt install -y python3-venv
$ mkdir project
$ cd environments
$ python3 -m venv my_project
  1. You can run your python projects in the virtual environment now.
$ source my_project/bin/activate

Different Data Types in Python

In Python, several built-in data types can be used to store and manipulate different kinds of data. Some of the most common data types in Python are:

  1. Numbers: Numbers in Python can be of different types such as integers, floating-point numbers, and complex numbers.

    • Integers represent whole numbers (both +ve and -ve).

    • Floating-point numbers represent real numbers with a decimal point.

    • Complex numbers represent numbers in the form a + bi, where a and b are real numbers and i is the imaginary unit.

  1. Strings: Strings are sequences of characters enclosed in single or double quotes. They can be used to represent text and can be manipulated using various string methods.

  2. Booleans: Booleans represent either True or False values and are used to evaluate conditions in conditional statements.

  3. Lists: Lists are ordered collections of items enclosed in square brackets. They can contain items of different data types and can be modified using various list methods.

  4. Tuples: Tuples are similar to lists but are immutable, which means that they cannot be modified after they are created.

  5. Sets: Sets are unordered collections of unique items enclosed in curly braces. They are used for operations like set intersection, union, and difference.

  6. Dictionaries: Dictionaries are collections of key-value pairs enclosed in curly braces. They are used to store and retrieve data using keys instead of indexes.

In addition to these built-in data types, Python also allows users to define their custom data types using classes and objects.

Reference: Check the complete Playlist here.

*****************************************************************************

Thanks for reading! Hope you find this helpful.

Happy learning ๐Ÿค—

Suggestions are always welcome.

~Sumit

Thank You - Shubham Londhe

ย