fbpx

Essential Python Commands and Libraries for New Programmers

Essential Python Commands and Libraries for New Programmers


INTRODUCTION

Python is a versatile language with a simple syntax, making it a popular choice for both beginners and experienced developers. In this blog, we’ll cover the essentials of Python, starting from installation, basic commands, and the foundations of Python coding that every programmer should know.

Starting with Python setup, we’ll walk you through downloading and installing Anaconda, a comprehensive package manager that simplifies Python environment management and offers useful tools like Jupyter Notebook for interactive coding. We’ll also explore key concepts such as adding comments, importing libraries, and using basic commands to assign variables, check print options, and understand fundamental operators.

Python installation and python version

– Comments in python

– Basic commands

 – Import libraries

 – Checking print options

 – Assigning and storing variables

 – Checking a few operators

 – Lists, Dictionaries and Sets in Python (will learn in detail in later courses)

– Packages Overview

  – Numpy

  – Pandas

– Jupyter shortcuts

 

Python installation

–  install Anaconda Individual Edition (based on the compatibility).

  1. Search for Anaconda Navigator on your system .
  2. A navigator window will appear, displaying pre-installed packages available in Anaconda, including JupyterLab, Jupyter Notebook, PyCharm Professional, RStudio, and more.
  3. Launch Jupyter Notebook from the Navigator.
  4. This will open an editor in your default browser, where you can access any existing .ipynb file or create a new one.

Comments in python

-For single line comment we use#

Use # to single line comment

 

For multi line comments

(‘’’) triple single quotes

(“””)triple double quotes

This is known as a docstring in Python and is typically used inside functions to describe their purpose and functionality.

– Import libraries

———————

 

Import numpy as np;

Import pandas as pd;

Import scipy;

 

Checking print options

 

print(“Learning python is good”)

print(12)

printf(“34”)

 

– Assigning and storing variables:

 

var1 = 16 #int type

var12=15

var2 = 4.0         #float type

var3 = “hello” #string type

var4 = ‘345’ #string type

var5 = True #bool type

 

– Checking a few operators:

 

# Add two numeric variables

print(var1+var2)

#subtract

Print(var1-var2)

#multiplication

Print(var1*var2)

#division

Print(var1/var2)

# Square

print(2**2)         

var1=1

str=thenmozhi

print(var1+str) ## integers and string cannot be added.

XOR OPERATION

———————–

print(var1^var12)

List

—–

#Example

l1 = [‘learning’, “Python”, ‘is fun?’, True,5]

print(l1)

Tuples

——-

 

#Example

l2 = list((“learning”, “for”, “life”, True))

print(l2)

 

l1.append(10) #add at the end of the given list

l1

l2.remove(learning)

l2

# Join two lists

l1 = [‘learning’, “Python”, ‘is fun?’, True]

l2 = list((“learning”, “for”, “life”, True))

l1+l2

#Use standard functions

l3 = [2,4,6,8]

range = max(l3) – min (l3)

range

max(l3)

mean = sum(l3)/len(l3)

mean

 

numpy:

import numpy as np

 

simple_list = [101,102,103,104,105,106,107,108,109,110]

print(simple_list)

 

type(simple_list)

list of list

———–

simple_list_of_lists = [[10,11,12],[20,21,22],[30,31,32]]

simple_list_of_lists

 

np.array(simple_list_of_lists)

 

print(“1.”,np.zeros(10))    # Specify the count of 0’s required in the array

 

print(“\n2.\n”,np.zeros((4,3))) # Specify the number of rows by columns – 4 rows and 3 cols in this example

 

Random numbers

  1. rand
  2. randn
  3. randint

np.random.rand(10)

  • Description: Generates random numbers from a uniform distribution over the interval [0, 1).

np.random.randn(4,4):generates the numbers from  0 to 1  in 4 by 4  matrix

 

  1. randint –specify the lowest and highest range,so that generates the random number between the specified range.

Ex:

np.random.randint(1, 100) # generates the random number between 1 to 100