-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPython notes
More file actions
108 lines (65 loc) · 3.98 KB
/
Python notes
File metadata and controls
108 lines (65 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
WHY PYTHON ?
``````````
-simple syntax and short -compared to other languages like - java
-hackers prefer python for its ease of use
-library support-lots of inbuilt functions-powerful web application development
-very productive programming - time required to code is less.
-object oriented
-community support - for all developer/hacker/newbie/programmer
-fastest growing language - in terms of
- number of users & companies
- number of libraries
- areas of implementation (machine learning, gui,scientific calculations, web & software development)
-General purpose language, simple & easy to learn ( Data scientists & Data researchers wanted a simple language to learn faster by spending less time on coding)
-Interpreted language ( needs an interpreter to run code) object oreinted & highlevel language
-was invented way before java in 1989
-used by companies like google,nasa,dropbox, yahoo, youtube, reddit (completely built on python) etc
---------------------------------------------------------------------------------------
PYTHON INSTALLATION:
```````````````````
-Download python installation package from official website & install(use google for instructions - especially while installing on linux machine.)
-python versions - 1.x,2.x,3.x - currently 3.x is in trend with lots of new features though 2.x is still running in market
-setup the environment for running python (from command prompt/IDE)
-Need an interpreter since its an interpreted language
-Need an IDE - Integrated Development Environment - to build an application we need to build a project and code-debugging facility
-Pycharm
-IDLE
-Anaconda
WHY DO WE CODE ?
``````````````
-To talk to computer and get the work done.
-Computer cant understand human speaking english. It can understand only binary language whereas Human cant understand binary language but english.
-Coding is a language which both human & computer can understand.
-So when we write a code instructing computer to perform certain task, it is converted into binary language instruction and the work is completed by computer.
Variables & Operators -
``````````````````````
A variable denotes the name of the location where a value is stored. We can change it whenever we want and hence the name.
we can assign a value to a variable - it can be of any data type and we can perform multiple operations on them
while working with operators like + - * / % // - BODMAS principle is applicable
while performing division operation : / gives quotient exact value , // gives rounded off quotient value, % gives reminder value
we can add a predefined string with a new string using + operator and we call it concatenation
also we can add two strings using + operator
we can use inbuilt function len() to find length of a string
Strings are immutable and hence we cant change the predefined string& its characters
But we can use indexes to select particular part of a string and append it with some othe characters
we can print characters of a string using notation string[x:y] here x denotes - starting index , y denotes last index but o/p returned will be till y-1 index
we can use inbuilt function type() to get datatype of the particular variable
when we use negative indexes on strings eg: String[-3] - it returns the character r from the right(reverse) in the below string
I m r a n
0 1 2 3 4
-1 -2 -3 -4 -5
LIST
-Mutable - can play around with inbuilt functions like add, append, remove, del, pop, extend, sum, min, max, sort etc;
-we can anytime change the contents of the LIST anytime
-it can accommodate different datatype values - int, float, string
- represented in square brackets - []
TUPLE
-Immutable - cannot change the contents of tuple anytime.
-[:] slicing option doesnt work in tuple
-represented in { }
SET
- supports sequence of values of different datatypes
- represented in ()
- slicing option doesnt work [:]
-always returns sorted values when the set contains all values of similar datatype
-doesnt return duplicate values