Learn Python - Day One !!!

image

Hello EveryOne, Today we will learn Python Programming language in a basic and easy manner. Let's make it happen.

Lets starting with definition

Python is a High level general programming language. Its syntax is as similar like English. and it's syntax is so easy to understand. here, You will be able to make a 2D game in python in just 200 lines only. In any other Programming, its impossible.

Code length Comparison

Applications of Python

  • Game Development
  • Face Recognition
  • WebSite Development
  • Robot Programming

Now, Lets start the Programming in Python

  • First of all go to https://www.python.org and Download the latest version of python(Currently is 3.7).
  • After Downloading, Install the Setup by double clicking on the python3.7.0.exe file.
  • then a diaglog box appear like this (then Follow the steps as shown)
  • then Launch the IDLE from the window searchbar.

Now Lets Start Our First Python Code

Lets make a program to enter any name and display it.

Now Proceed with one more example

Lets make a program to add two numbers

Solution :

How to take User input in Python

Input can be taken from keyboard in python using input() function

Solution :

name = input(" Enter name : ")

Output: Enter name : Brain-Mentors

IF - ELSE in Python

The if-else statement is used to conditionally execute a statement or a block of statements based on required condition. Condition can be true or false, execute one thing when the condition is true, something else when the condition is false.

Lets take an example that we have to find number is even or not

Solution :

Output:

LOOPS

Loop means basically repeatition.

lets talk about programming view of loop, here if we want to repeat the code as required times, we can put it in a loop In Python, There are only Two types of Loops

  1. FOR Loop
  2. WHILE Loop

FOR LOOP

for loop in Python is used to iterate over a sequence (list, tuple, string) or other iterable object

lets take an example, print a star pattern using for LOOP.

Solution :

Output :

Lets take an another example, print number from 1 to 10 using for-loop

Solution :

Output :

WHILE Loop

The while loop is used to iterate over a block of code as long as a given condition is true. Lets Understand the While Loop by taking an example.

Print number from 1 to 5 using while Loop

Solution :

Output :

LISTS in Python

list is a type of Data Structure as like Stack, which is used to store multiple data(data can be similar or dissimilar) at the same time.

List Syntax:

Operations on List

  • Append items in a List

    If we want to add items to a List. We can insert elements by using Append Function.

    if we want to insert element at specified index, then use insert() function.

  • delete items List

    If we want to delete itmes from existing List. We can do it by using pop() Function.

Now, Lets take an Example

Find the Reverse of an existing list

Solution

TUPLE

Just like lists , Tuples are sequences but are of immutable type. Immutable means it can't be changed(Updation/deletion operations can't be implemented on tuples).

Tuple Syntax:

Dictionary

A dictionary in Python is just like a English dictionary.

Python Dictionary is a set of key:pair value. Keys will be a single element, but Values can be a list or list within a list, numbers,etc

Accesing values in Dictionary

To access dictionary's elements, you can use the familiar square brackets along with the key to obtain its value.

Updating Dictionary

You can Update dictionary by adding new entry or a key value pair.or can also modify the existing entry.

Delete Dictionary Elements

You can remove individual dictionary elements or clear the entire content of a dictionary. You can also delete entire dictionary in one go.