Saturday, 4 January 2020

Variables in Python

Introduction:
    Variables are containers that hold values in the computer memory; We use variables in our program for various kind of manipulations.
    Variables are containers for holding values of different data types.
    The variable might be belonging to any of the data types like Numbers, String, List, Tuple, Dictionary, etc.
    The value of the variables may change in the program.
    Python is a dynamically typed language, so the declaration of data type is not required. See Duck Typing

Rules for naming variable:
      1. Variable names are case-sensitive.
               In this, uppercase and lowercase letters in the variable name treated as distinct. That's why result, Result, RESULT are three different variable names.

2. A variable name must start with a letter or the underscore character.
               A variable name cannot start with a number.

      3. A variable name can only contain alpha-numeric characters (A-z, 0-9) and underscores ( _ ).



We assign value to the variable using the Assignment operator (=).
Python also allows us to assign values to multiple variables in a single line.








Thursday, 3 October 2019

Getting Started with Python

        Python runs on almost any operating system. In many operating systems it's already installed. You can check whether Python is installed on your computer or not simply by running following command:
python --version




If python is already installed on your computer then the above command will show the version of python.

If python is not installed on your machine then you can download the latest version of python from the following link: https://www.python.org/downloads/

To edit the python code we need a text editor. We can use notepad, vi, gedit, etc. to edit python code. but I recommend using editors like VS Code, Atom, Notepad++, etc, as they offer facilities like IntelliSense code completion and debugging, syntax highlighting, auto-indentation, and much more.

Python code file has a .py extension. To execute our program we need to follow the following command:
  1. Open text editor and write following statement in it, and save as firstprogram.py
  2. To run the source code file follow the following command:










Tuesday, 16 July 2019

Object oriented programming concepts

      

        Object-Oriented Programming (OOP) is one of the programming paradigm or programming style. Popular programming languages like Python, Java, C++, etc. follows an OOP paradigm.
OOP is not the only style of programming. If you know C language and have done some coding in C, then you have followed Procedure Oriented Programming (POP) paradigm.
        Procedural programming is suitable for small projects; as size increases, it's complicated and hard to manage.
        We can program in both paradigms; OOP provides some additional features over POP like encapsulation, inheritance, polymorphism, etc.
Data is a valuable asset to any organization; So it's important to give security to it.
        The POP approach is less concern about data security. OOP's central focus is on data security.

Class and Object :
        A class is a blueprint or prototype for creating objects.
        A class defines attributes and functions for an object.
        An object is an instance of a class.
        If you take "mango" as an object; then "fruit" is a class.
Similarly, if you take "tiger" as an object; then "animal" is a class.
        A class is also known as an Abstract Data Type (ADT). You will understand why it is called ADT by the following example.
        If I told you to draw a fruit; you will ask me which fruit? , because you know there are a variety of fruits with different shape, color and taste. but if I told you to draw "mango" then you will be able to draw "mango" without confusion.
        You can draw a "mango" because of its a real thing whereas "fruit" is just a blueprint or abstract thing.

Encapsulation :
        Encapsulation is a mechanism for wrapping up the data and code into a single unit (generally into class).
        Encapsulation provides security to your code.

Inheritance :
        In inheritance, one class acquires the properties of another class.
With inheritance, we can extend the class with additional attributes and methods.
        A class from which new class is created is known as the superclass or parent class, and the new class is known as subclass or child class.
Child class contains all the data & methods of a parent class as well as its own.
        Consider a parent class "mobile-phone" with attributes name, model, weight, speaker; and with functions makeCall(), receiveCall(), sendSMS(), etc. If you extend the class "mobile-phone" with the class named "smartphone" then the class "smartphone" will have all the attributes and methods of the class "mobile-phone" as well as its own attributes camera, gyroscope-sensor and functions capturePhoto(), browseInternet(), etc.

Polymorphism :

        "Poly" means many and "morph" means form. The ability of an object, variable, or function to take more than one form is known as polymorphism.
        Consider two methods calculateArea(radius) and calculateArea(length, width). If we provide a radius; the first function gives an area of a circle. If we provide length and width; the second function gives an area of a rectangle.
In the above example, we used the same function name with a different prototype.

There are two types of polymorphism :
  1. Compile-time polymorphism
  2. Run-time polymorphism


Saturday, 22 June 2019

Introduction to Python Programming

       
       
        Python is a high level programming language which was created by Dutch programmer named Guido van Rossum in 1990.



Features of Python :
  • Easy to Read & Code : 
    • Any program (instructions/statements that performs a specific task.) having proper indentation is easy to read.
    • In a programming language like c, c++ we use curly braces for grouping statements. Python doesn't use brackets for grouping of statements. In Python "Indentation" shows where the group of statement starts and where it ends.
    • Python uses English keywords thats why its easy to code in Python. By just reading statements we can tell what it does. 
  • Open Source :
    • Open source programming language refers to programming language whose source code is freely available on the internet and we can redistribute and modify it.
    • Because of this feature we can use python for our commercial use.
  •  Object Oriented Programming:
    • Python supports Object Oriented Programming (OOP) paradigm.
    • OOP has more advantages (advantages of Encapsulation, Inheritance, Polymorphism etc.) than procedural programming.
    • For the real world problem OOP is more suitable than any other programming paradigm.
  • Large amount of Standard Libraries : 
    • In programming, library is a collection of functions (Function is a block of code which performs specific task.) that allows you to perform various task effortlessly.
    • In Software or Web development libraries savesmuch more time hence also reduces cost of project.
    • numpy, scipy, pillow, pandas are some of Python's popular libraries.
Python is used in -
  • Web and Internet Development
  • Database Access
  • Desktop GUIs
  • Scientific & Numeric computing
  • Education
  • Network Programming
  • Software & Game Development

Wednesday, 5 June 2019

What is programming language and algorithms.



Programming Language : 
        We use native languages like English, Marathi, Hindi etc. to communicate ๐Ÿ—ฃ with each other. but how we can communicate with computer ? ๐Ÿค”  How we can accomplish our work from computer ? ๐Ÿค”
   
        Computer ๐Ÿ’ป is just a mechanical device and has no intelligence like human have. It works accordingly to the algorithm provided by computer programmer. ๐Ÿค“

        As we understand native languages; computer understands programming languages. There are many programming languages and the popular among them are C, C++, Java, Python etc.

        Programming language consists of set of instructions; ๐Ÿ“ with these instructions computer program produces output.
         Programming languages are mainly classified into two types, low level languages and high level languages.

Low level languages :
        Did you ever think why we use decimal number system in our daily life? ๐Ÿค” It's because we all have 10 fingers. ๐Ÿ˜Š Our ancestors used fingers for counting and calculating. so it's natural to adopt this number system in our daily life.
        In a same way computer have transistors with two states (ON or OFF). Computer is made up of electronic circuits and those circuits can do nothing more than passing electricity. ๐Ÿ˜ฎ This electricity have two states ON and OFF (presence and absence of electricity). These two states are represented by 0 and 1 and known as binary language or machine language of computer.
        Machine code (stream of 0's and 1's) is directly implemented on CPU (Central Processing Unit). that's why time taken by machine code to execute is very small as compared to other languages; but machine code is difficult to understand and write. ๐Ÿ˜ง
        Assembly language is also type of low level language in which programmers work only with operations. Assembly language have set of commands like ADD, MOV etc. Assembly language is still useful when speed is necessary or when we need to carry out an operation which is not possible in high level languages.

High level languages :
        Do you ever think why we invent things ? ๐Ÿค” We invent because we want to make things easier. for example we invented bicycle ๐Ÿšฒ or bike ๐Ÿ because we want to go faster from one destination to another than walking ๐Ÿšถor running ๐Ÿƒ‍. but we didn't stop there we again invented car ๐Ÿš— because we wanted more comfort while travelling. So making thing easier is in the nature of the human being. In a same way we developed high-level programming languages for the ease of writing programs.
        High level programming language is generally written using English keywords and that's why it's easy to understand and write. High-level languages takes more time ๐Ÿ•ฐ to produce output than low level languages because high level languages need to be converted into low level languages using compiler or interpreter. (I will make a separate post on compiler and interpreter)



Algorithm :  
        An algorithm is a set of instructions designed to perform specific task.
        In our daily life we also use algorithms to do specific task to get desired output. You may know how to make a tea, ☕ for making a tea we use following algorithm :


  • Step 1 : Turn on burner. ๐Ÿ”ฅ
  • Step 2 : Take a pan and add water, tea leaves and sugar to it. 
  • Step 3 : Heat the tea until it turns a reddish brown colour. ♨
  • Step 4 : Add milk to the mixture. ๐Ÿผ
  • Step 5 : Stop the burner when the milk rises to the top of the pan.
  • Step 6 : Filter all the solid out (tea leaves).
  • Step 7 : Serve Kadakk chai (hot tea). ☕๐Ÿ˜‹

In a same way we can have algorithm (step-by-step procedure) to perform addition of two numbers given by user :

  • Step 1 : Start
  • Step 2 : read two numbers.
  • Step 3 : Perform addition of numbers given by user.
  • Step 4 : Display addition.
  • Step 5 : Stop.
Next post will be on "Introduction to Python" ๐Ÿค—


Click here ๐Ÿ‘ˆ to add yourself to the Google group so you don't miss any updates.

Saturday, 1 June 2019

First post on programming book which I am going to write ๐Ÿ˜Š

   
    The thought that I must write a book on programming excited ๐Ÿค— me all the time.
   
    Knowledge ๐Ÿ“– has no value unless you use and share it, so I decided to share my little knowledge about computer programming with you.

 

    I will write this book in series of posts which I will post regularly on my blog.

below is the form where you can give me your email so when new post comes you will get notified by e-mail immediately.

https://docs.google.com/forms/d/e/1FAIpQLSfNyZzqW0HfLCeGMJ5a_XZzsS_TbqWXAaWgGPup6NShzY9nsQ/viewform

Thanks for clicking ๐Ÿ™ I will catch you in next post ๐Ÿ™‹