Lesson 2: Classes and Functions

What is a class?

This defines a set of attributes that will characterize any object that is instantiated from the class. Python is based on OOP’s concept i.e Object Oriented Programming which means you don’t have to write the same program for different devices. If you write a program for a mobile phone it can also be used for a laptop or desktop. To call a function form a class we can do <class name>.<function name>(parameters if there)

let me show you an example of a class

Capture

Capture

What is a function?

A function is always defined by the keyword ‘def’. Take the above example of a class where def addition is a function. There can be multiple functions in a class.For clear understanding think a python class as a regular classroom and function as a student in that classroom.Let you show you a simple calculator based on this understanding.

Capture

here calculator.multiplication is calling the function multiplication and the parameters in(3,5) are the values assigned to x and y respectively.

Try this program out in your IDLE with different values of x and y. Last but not the least there are two division symbols in python which are ‘/’ and ‘%’. the first one i.e called ‘by’ gives the quotient as the output answer and the second one called modulus gives remainder as the answer.

Once again thank you for reading and if you have any doubts feel free to contact me by commenting or emailing me

 

 

Lesson3: Loops

A loop is used to make a jump.

We are going to discuss ‘for loop’ and ‘while loop’.

While loop

Syntax: while <condition> ‘< or >'(lesser than or greater than) <condition>.No miracles happened here I will explain you everything. But before going to condition let me explain you a simple statement.

let for example here initilize a number to a variable

>>a = 10

>>>a+= 10

>>print(a)

What this will do is first ‘a’ is equal to 10 and ‘a+’ means/equal to ‘a = a+10’. (Kinda seems difficult to understand but it’s a simple logic). Capture.PNG

let’s take an example of while loop now

 

Capture

try this program out and comment the output below

For loop

For loop is used to illerate through a list.(do not worry about what is a list my next post will be on lists)

Capture

here examplelist is the list name, x is any variable used to store illearted value

Try both the loops in your terminal or IDLE and comment me the answer if you have any question feel free to ask in comments or email me, Once again thank you for reading just wait for a week and we will be done with basics and going for machine learning

Lesson 1:Basics

What are variables?

A variable is any character or word used to store a memory location.Eg  ‘a’ , ‘b’ etc..   You can store or allocate memory using a ‘=’ equal to symbol. For example a = 10. This means you have stored the value 10 in a.

Open your python terminal and type the following

Capture

What are comments?

Comments are used to write a brief note about the code/program you are working on.   ‘#’ is the symbol for comment in python. Python just ignores all the stuff after #. It is a signal line comment. Eg

Capture

Here you can see python just ignored everything after #. Multiline comment is ”’       ”’ .

Note::

If you are familiar with any other programming language then you must have never cared about spaces between line to next line because most of the programming languages ignore it and do not give a syntax error but in Python3 you must have a 4 space between classes and next line. DONT WORRY ABOUT TERMINOLOGY HERE I WILL TEACH YOU EVERYTHING.

Always remember the more you practice the better you understand.

Thank you for reading I will be uploading continuously till we complete python3 basics if you have any question regarding my content feel free to comment.

 

 

 

Getting started with Python

Why choose Python over any other programming language?

Well, every programming language has its own use. For example, Java is used for many things including to create great Android apps, websites etc, SQL is used to a write database of any website including one which you are already reading, Javascript is used to design websites(along with CSS).Now python on other hand is very vast language and also has an easy syntax compared to other programming languages.once you have passed python basics you can do very cool stuff with python including creating your own games, learn machine learning, learn raspberry pi to control hardware with python and many more things.

So let’s get started

Here is assume you have very little or no programming knowledge. First, let’s install python on our machine.You can have any OS running I have windows 10. So to install python on windows 10 you need to download a zip file from here choose python3 extract the zip and run the setup file.

Installing in Linux distro

just download the zip file(Linux supported one of course) save it on the desktop.Open your terminal and type the following commands.

root@kali:cd Desktop

root@kali:ls

root@kali:cd

root@kali:ls

root@kali:./configure

after the program stopps

root@kali:make install

There you go python3 is installed on your Kali Linux machine. Sorry MAC users I have never owned or used a MAC but you can google “how to install python3 on a MAC”.

Thank you for reading next post I will be starting fundamentals in python, I won’t take too many posts but will cover everything in 10 posts more or less. After that, I will teach you Machine learning and coding games and also python with hardware