the awesome python class part-2

13
The Awesome Indents, pip, virtualenv, basic data types and data structures. Part-2

Upload: binay-kumar-ray

Post on 22-Jan-2018

129 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: The Awesome Python Class Part-2

The Awesome

Indents, pip, virtualenv, basic data types and data structures.

Part-2

Page 2: The Awesome Python Class Part-2

Summary of Part-1

In the first part we have installed python. Setup editor and checked with pip.

This part we will get to know how to write a basic python code. Dig into pip and

virtualenv, and learn about data types and data structures.

2

Page 3: The Awesome Python Class Part-2

Set up environment to start

PIP

Its Python Installer Package.

Python is so well designed and managed

that you don't have to do anything

manually, just type pip install package

name and bang.

Its can handle multiple python version and

multiple pip version on a single machine.

Virtual Environment

It's creates the necessary development

environments on the same systems so

that user can use multiple software

version in one machine.

For this tutorial we will not use any

environment as its simple python

learning.

In the next play list of web development we

will go for it.

3

Page 4: The Awesome Python Class Part-2

Python Code

There are certain things that can make you feel like a king while writing code.

First of all add the following list of plugins to your sublime text and follow proper

coding styles. As we have discussed in the first part there is no braces in python

and hence code block is distinguished by indents. A good coding practice follow

4 space indent for one block.

It might confuse you at first if you are following conventional languages like c or

java but then you will feel more comfortable and readable code.

4

Page 5: The Awesome Python Class Part-2

Hello world

Done! Only a line that too way too readable. Isn’t it great.

5

Page 6: The Awesome Python Class Part-2

Enjoying?

Lets swap two variables

6

Page 7: The Awesome Python Class Part-2

Datatypes

Unlike any other languages you don’t need to define the variable type every time

before using it.

I mean suppose now variable x = 2 now type(x) is int, in the next line is x = 2.5

type(x) will be float, the very next line assign x = ‘India’ and its str now.

so it’s kind of generic where you don’t need to define like int x = 1, like you do in

C or java and that makes typecasting super easy in python. That’s the

awesomeness of python.

So basically we have the same data types in python int, float, str.

7

Page 8: The Awesome Python Class Part-2

Basic Data Structures

Here comes one of the most important

concepts of python,

MUTABLE & IMMUTABLE

Mutable means “liable to change” meaning you

can change the values but Immutable you can

not change the values.

There are 4 basic data structures available in

python.

● List

● Dictionary

● Tuple

● Set- List is like and arrey.

- Dictionary is like hash table that has key value pair.

- Tuple is like list but immutable.

- Set is used as data structured to define mathematical sets.

8

Page 9: The Awesome Python Class Part-2

Lists

List behaved exactly like arrey, It’s a sequence, enclosed with [ ] and separated

by ‘ , ‘ .

9

Page 10: The Awesome Python Class Part-2

Tuple

Tuple is same as list, But it is immutable. You can not alter the value of a tuple

with your code. It is enclosed by ( ).

10

Page 11: The Awesome Python Class Part-2

Dictionary

Dictionary is enclosed by {} and have key value pair. It is the most important

data structures of python. It’s handled as a hash table in backend.

11

Page 12: The Awesome Python Class Part-2

Set

Set acts as mathematical set to represent data.

12

Page 13: The Awesome Python Class Part-2

ThanksStay Tuned for the next part. Enjoy !!

13