Python IDE

Gents! Welcome to Neural Bots Exclusive E-Learning page focusing on the basic concepts on Python Development Environment. This course is tailor made to Horne your coding skills to work in the field of Data Science and Machine Learning.

Besides, after you complete the basic course on programming using Python, you will be able to develop the Games available under the Games section of Neural Bots. ‘Sky is the limit for your imagination’. Jump right in and start the course.

You can test the output of any Python code of .py extension, under the Trinket io, which is your Online Python Interpreter. You can find the interpreter, by clicking on the ‘Python Interpreter’  link available in the contents. 

For Starters we can start coding in python v3.8.3 IDLE which is the basic Integrated Development Environment. In upcoming courses we shall explore other environments like Pycharm, Sypder, Jupyter and Anaconda which is a free and open-source distribution of the Python and R programming languages for scientific computing.

We will covering all the major concepts of python, how it is different from its predecessor like C or C++, the concept of Object Oriented Programming Approach, 

Happy Learning!

Top News

Table of Contents

Basics of Python Tutorial

Python is a high-level programming language and is widely being used among the developers’ community. Python was mainly developed for emphasis on code readability, and its syntax allows programmers to express concepts in fewer lines of code. Python is a programming language that lets developers work quickly and integrate systems more efficiently.

This Python 3 tutorial provides learners (either beginner or experienced developer) with the topics from Python basics to advanced topics with examples.

Features of Python

Python has many reasons for being popular and in demand. A few of the reasons are mentioned below.

  • Emphasis on code readability, shorter codes, ease of writing.
  • Programmers can express logical concepts in fewer lines of code in comparison to languages such as C++ or Java.
  • Python supports multiple programming paradigms, like object-oriented, imperative and functional programming or procedural.
  • It provides extensive support libraries(Django for web development, Pandas for data analytics etc)
  • Dynamically typed language(Data type is based on value assigned)
  • Philosophy is “Simplicity is the best”.

Getting Started with Python

Installation of Python IDE

Let’s confirm if python is installed in your system?

In the Command prompt cmd run the following command :

If Python is already installed, it will generate a message with the Python version available.

python3 –version

Download and Installation

Before starting with the installation process, you need to download it. For that all versions of Python for Windows, Linux, and MacOS are available on python.org.

How-to-install-Python-for-windows-11

Download the Python and follow the further instructions for the installation of Python.

Beginning the installation.

  • Run the Python Installer from downloads folder. Make sure to mark Add Python 3.7 to PATH otherwise you will have to do it explicitly.
    It will start installing python on windows.
    python-install-windows-1
  • After installation is complete click on Close.
    Bingo..!! Python is installed. Now go to windows and type IDLE.

How to run a Python program

Let’s consider a simple Hello World Program.

Generally, there are two ways to run a Python program.

  • Using IDEs: You can use various IDEs(Pycharm, Jupyter Notebook, etc.) which can be used to run Python programs.
  • Using Command-Line: You can also use command line options to run a Python program. Below steps demonstrate how to run a Python program on Command line in Windows/Unix Operating System:

Open Commandline and then to compile the code type python HelloWorld.py. If your code has no error then it will execute properly and output will be displayed.

Fundamentals of Python

Python Indentation

Python uses indentation to highlight the blocks of code. Whitespace is used for indentation in Python. All statements with the same distance to the right belong to the same block of code. If a block has to be more deeply nested, it is simply indented further to the right. You can understand it better by looking at the following lines of code.

 

The lines print(‘Logging on to NeuralBots…’) and print(‘retype the URL.’) are two separate code blocks. The two blocks of code in our example if-statement are both indented four spaces. The final print(‘All set!’) is not indented, and so it does not belong to the else-block.

Note: For more information, refer 👉🏽 Indentation in Python.

Python Comments

Comments are useful information that the developers provide to make the reader understand the source code. It explains the logic or a part of it used in the code. There are two types of comment in Python:

Single line comments: Python single line comment starts with hashtag symbol with no white spaces.

Multi-line string as comment: Python multi-line comment is a piece of text enclosed in a delimiter (“””) on each end of the comment.

Variables

Variables in Python are not “statically typed”. We do not need to declare variables before using them or declare their type. A variable is created the moment we first assign a value to it.

Operators

Operators are the main building block of any programming language. Operators allow the programmer to perform different kinds of operations on operands. These operators can be categorized based upon their different functionality:

  • Arithmetic operators: Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication and division.

Relational Operators: Relational operators compares the values. It either returns True or False according to the condition.

Logical Operators: Logical operators perform Logical AND, Logical OR and Logical NOT operations.

Bitwise operators: Bitwise operator acts on bits and performs bit by bit operation.

  • Assignment operators: Assignment operators are used to assign values to the variables.
  • Special operators: Special operators are of two types-
    • Identity operator that contains is and is not.
    • Membership operator that contains in and not in.

Basics of Input/Output

Python provides us with two inbuilt functions to read the input from the keyboard.

  • raw_input(): This function works in older version (like Python 2.x). This function takes exactly what is typed from the keyboard, convert it to string and then return it to the variable in which we want to store. For example:
# Python program showing  
# a use of raw_input() 
    
g = raw_input("Enter your name : "
print g
  • input(): This function first takes the input from the user and then evaluates the expression, which means Python automatically identifies whether the user entered a string or a number or list. For example:
# Python program showing  
# a use of input() 
    
val = input("Enter your value: "
print(val)

Printing output to console

The simplest way to produce output is using the print() function where you can pass zero or more expressions separated by commas. This function converts the expressions you pass into a string before writing to the screen.

Data Types

Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes.

Numeric

In Python, numeric data type represent the data which has numeric value. Numeric value can be interger, floating number or even complex numbers. These values are defined as intfloat and complex class in Python.

Sequence Type

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

  • String
  • List
  • Tuple

String

A string is a collection of one or more characters put in a single quote, double-quote or triple quote. In python there is no character data type, a character is a string of length one. It is represented by str class. Strings in Python can be created using single quotes or double quotes or even triple quotes.

Accessing elements of string 

Deleting/Updating from a String –

In Python, Updation or deletion of characters from a String is not allowed because Strings are immutable. Only new strings can be reassigned to the same name.

List

Lists are just like the arrays, declared in other languages. A single list may contain DataTypes like Integers, Strings, as well as Objects. The elements in a list are indexed according to a definite sequence and the indexing of a list is done with 0 being the first index. It is represented by list class.

Adding Elements to a List: Using append()insert() and extend()

Accessing elements from the List –

Use the index operator [ ] to access an item in a list. In Python, negative sequence indexes represent positions from the end of the array. Instead of having to compute the offset as in List[len(List)-3], it is enough to just write List[-3].

Removing Elements from the List: Using remove() and pop()

Tuple

Tuple is an ordered collection of Python objects much like a list. The important difference between a list and a tuple is that tuples are immutable. It is represented by tuple class. In Python, tuples are created by placing a sequence of values separated by ‘comma’ with or without the use of parentheses for grouping of the data sequence.

Accessing element of a tuple

Use the index operator [ ] to access an item in a tuple.

Deleting/updating elements of tuple –

Items of a tuple cannot be deleted as tuples are immutable in Python. Only new tuples can be reassigned to the same name.

# Python program to  
# demonstrate updation / deletion 
# from a tuple 
    
tuple1 = tuple([1, 2, 3, 4, 5])
    
# Updating an element
tuple1[0] = -1
    
# Deleting an element
del tuple1[2

Boolean

Booleans are data type with one of the two built-in values, True or False. It is denoted by the class bool.

Set

In Python, Set is an unordered collection of data type that is iterable, mutable and has no duplicate elements. The order of elements in a set is undefined though it may consist of various elements. Sets can be created by using the built-in set() function with an iterable object or a sequence by placing the sequence inside curly braces {}, separated by ‘comma’.

Adding elements: Using add() and update()

Accessing a Set: One can loop through the set items using a for loop as set items cannot be accessed by referring to an index.

Removing elements from a set: Using remove()discard(), pop() and clear()

Dictionary

Dictionary in Python is an unordered collection of data values, used to store data values like a map. Dictionary holds key:value pair. Each key-value pair in a Dictionary is separated by a colon :, whereas each key is separated by a ‘comma’. A Dictionary can be created by placing a sequence of elements within curly {} braces, separated by ‘comma’.

Nested Dictionary:

Adding elements to a Dictionary: One value at a time can be added to a Dictionary by defining value along with the key e.g. Dict[Key] = ‘Value’.